Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

![]() |
![]() |
![]() |

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