Replacement newline sed

How to replace \ n with string using sed command ?

+5
source share
1 answer

This is rude because sed usually processes the string at a time:

sed -e :a -e N -e 's/\n/ /' -e ta input.txt

It is better:

tr '\n' ' ' < input.txt

I decided to replace the new line with a space. tr can replace only one character (or delete with the -d option).

Flexibility and simplicity:

perl -ne 'chomp;print $_," "' input.txt

Where "" is what you want instead of a new line.

+9
source

All Articles