Computing.Net > Forums > Unix > How sed can remove newline

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How sed can remove newline

Reply to Message Icon

Name: Tugudu
Date: November 27, 2004 at 08:11:43 Pacific
OS: Linux Debian 3
CPU/Ram: Pentium III 500Mhz, 192
Comment:

Since several years, I needed time to time a filter which can remove conditionnally a newline character. Now I have the solution as in this example:

test> cat in.txt | sed '/SCENE.*[^\.]$/N;s/\n */ /'

This command will join from the in.txt output the lines which contain the word "SCENE" and don't end with a dot character (".").

test> cat in.txt
ACTE V
SCENE IV. -- ELISE, MARIANE, FROSINE, HARPAGON, VALERE, MAITRE
JACQUES, LE COMMISSAIRE, SON CLERC.
SCENE II. -- MAITRE JACQUES, HARPAGON, LE COMMISSAIRE, SON CLERC.
SCENE V. -- ANSELME, HARPAGON, ELISE, MARIANE, FROSINE, VALERE,
MAITRE JACQUES, LE COMMISSAIRE, SON CLERC.

Thanks to Google who pointed me to the following thread at Computing.Net :-)

http://www.computing.net/unix/wwwboard/forum/5992.html

Many thanks to Joe who initiated the above thread and to Jim who provided the explanation I missed until now. Jim wrote:

"With sed the newline character would not be available for elimination with a substitution command without pulling a second line into the buffer with the N command."

Tug




Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: How sed can remove newline

How I can setup Solaris 2.6 for X86 intel www.computing.net/answers/unix/how-i-can-setup-solaris-26-for-x86-intel/559.html

how I can make ? www.computing.net/answers/unix/how-i-can-make-/6494.html

remove top line in file www.computing.net/answers/unix/remove-top-line-in-file/4769.html