Wednesday, August 17, 2005

Removing newlines from a file using sed

I kept forgetting this as I never really realized that sed is a line editor.
So the newline at the end of the line isnt available by default unless we create a multiline pattern space using N.

Anyways here is the sed command that does the magic.

$sed ':a;N;$!ba;s/\n//g' filename

Among other things it uses labels and N command. :)

0 Comments:

Post a Comment

<< Home