Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unix commandline for inline replacement of all newlines in file with <br>\n

sed 's/$/<br>/' mytext.txt

worked but output it all on the command line. I want it to just do the replacement WITHIN the specified file itself. Should I be using another tool?

like image 715
DrMHC Avatar asked Aug 17 '10 02:08

DrMHC


1 Answers

If you have gnu sed, you can use the -i option, which will do the replacement in place.

sed -i 's/$/<br>/' mytext.txt

Otherwise you will have to redirect to another file and rename it over the old one.

sed 's/$/<br>/' mytext.txt > mytext.txt.new && mv mytext.txt.new mytext.txt
like image 112
camh Avatar answered Nov 13 '22 20:11

camh