Daily Archives: 21 January 2015


Inline replacement of all newlines in file with br tag

In case you have some output you want to add it to an HTML document, you need to make some modifications to it to make it appear properly.

One of them would be to replace the newline characters with the <br> tag.

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

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

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

sed 's/$/<br>/' myTextFile.txt > myTextFile.txt.tmp && mv myTextFile.txt.tmp myTextFile.txt

If you want to perform this change on the results of another command (because you are redirecting it to an email client like mutt) you can use the following example

someCommand | sed 's/$/<br>/' | someOtherCommand