For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > October 2007 > line continuations









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author line continuations
William Pursell

2007-10-29, 4:23 am

I need to parse a stream which may contain line continuations,
and I want to view the continued lines as individual lines. I came
up with:

sed ':p /\\$/N; s/\\\n/ /; tp; '


This seems like such a common requirement, that I figure
there surely must be a more canonical/simple way to do it.
Any ideas?

(Sample run of my script, demonstrating most
of the cases I care about. Note that trailing spaces
do not constitute a line continuation:
$ cat input
line 1
line 2 \
continued
line 3 \
continued \
further
\
start of continued line
$ sed ':p /\\$/N; s/\\\n/ /; tp;' input
line 1
line 2 continued
line 3 continued further
start of continued line

--
William Pursell

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com