LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   redirection (https://www.linuxquestions.org/questions/programming-9/redirection-597182/)

kkpal 11-05-2007 12:05 AM

redirection
 
I want do this
cat abc.txt | tr -d '\n' > abc.txt
I want output in same file, How can I do?

acid_kewpie 11-05-2007 02:03 AM

you would want a temporary file, e.g. abc.temp which you then rename to abc.txt in a second command.

bigearsbilly 11-05-2007 05:36 AM

you want to remove all newlines you mean?

perl -i -pe 'tr/\n//d' file

acid_kewpie 11-05-2007 05:47 AM

no, his code is fine, but wants to put it back in the file he read it from. you could run it through ex nto acheive the same result i guess.

student04 11-05-2007 10:24 PM

Quote:

Originally Posted by acid_kewpie (Post 2948500)
you would want a temporary file, e.g. abc.temp which you then rename to abc.txt in a second command.

Right, so --
Code:

cat abc.txt | tr -d '\n' > temp && mv temp abc.txt
A bit crude, but it works.

I don't know anything about sed/awk but they could manage it without a temp file.


All times are GMT -5. The time now is 06:39 AM.