Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing newline sed [duplicate]

Tags:

replace

sed

How to replace \n from a line using sed command?

like image 935
ArK Avatar asked Sep 18 '09 05:09

ArK


People also ask

How do I get rid of the new line in awk?

Use printf() when you want awk without printing newline AWK printf duplicates the printf C library function writing to screen/stdout.


1 Answers

It's gross, because sed normally processes a line at a time:

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

This is nicer:

tr '\n' ' ' < input.txt

I chose to replace the newline with a space. tr can only replace by a single character (or delete with the -d option).

Flexible and simple:

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

Where " " is whatever you want in place of the newline.

like image 175
Jonathan Graehl Avatar answered Oct 03 '22 10:10

Jonathan Graehl