Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tr command not able to direct the Output?

Tags:

linux

sed

tr

I have got a file file.txt witch has got these entries

NY

LA

SF

I ran the command tr '\n' ',' < file.txt and it successfully deleted all of the newline characters.

I need all of this output in the same file.txt file, so I redirected the output like this

tr '\n' ',' < file.txt > file.txt,

but It does not put anything in the file.txt and the resultant file is empty, Can anyone explain to me why the output of tr is getting lost due to redirection.

like image 958
Dude Avatar asked Feb 03 '13 18:02

Dude


1 Answers

because it opens the output file first which deletes what is in the file and then feels nothing into the tr command and back out into the empty file

tr '\n' ',' < file.txt > file2.txt 

will work

like image 146
Vorsprung Avatar answered Oct 04 '22 14:10

Vorsprung