SUMMARY: Parse files w lines ending with escaped new-line

2007-12-24 20:51:00

I received three responses, the first and simplest wins my award for...
simplicity. The other two does essentially the same thing. Again this
list proves its superiority - Thanx to the responses, including any that I
have not received yet due to net-lag. Does anybody on this list still
remember the word lag?

Bertrand_Hutin at notes.amdahl.com
try this:
nawk '/\\$/{sub(".$","");printf "%s",$0;next};{print}' /etc/printers.conf |
grep $PRINTER

"JULIAN, JOHN C. (AIT)" <jj2195 at sbc.com>
script to remove escaped new-line

#!/bin/sh
# stripeol

sed -e ':start
/\\$/{
N
s/\\\n//
b start
} $1

----end of script----

it will accept input as either a file on the command line or by piping
ie: cat /etc/printers.conf | stripeol
or: stripeol /etc/printers.conf

Marcos Assis Silva <root at songa-monga.sercomtel.com.br>
I remember having to deal with that once, and I used something
in the line of:

nawk '{if (substr($NF,length($NF))=="\\")
printf("%s", substr($0,1,length($0)-1)); else printf $0}'

One should have performance concerns when resorting to it and
if the data volume to be processed is worth notice, but if not for the
performance issue, it should do the job.

My original question contained one lie (due to me not THINKING); I quote it
for referential purposes:

>From: Johannes J Hartzenberg [mailto:jhartzen at csc.com]
>Sent: Friday, September 21, 2001 10:08 AM
>To: codeprof at codeprof.com
>Subject: Parse files w lines ending with escaped new-line
>
>
>Hi,
>
>I want to parse /etc/printers.conf in a script, specifically to get the
>description field for a specified printer, along the lines of
>
>
>cat /etc/printers.conf | reformat | grep "^${PRINTER}:" | awk -F: 'print
>($3)'
>
>a normal grep xxx /etc/printers.conf appears to work but it only returns
>the first line and the line following each hit.
>
>Strangely enough, cat -e /etc/printers.conf doesn't admit to finding ANY
>end-of-line
>characters!!!
>
>How do I do the "reformat" bit in the command to turn each entry in the
>/etc/printers.conf file into a single line with fields colon-separated and
>records separated by newline?
>
>Thanx in advance,
> _Johan

P.S. Allow me a small flame: I reply to many questions, but very seldomly
see any Summaries. This list is supposed to be a shared learning medium
(In addition to assisting us all out of difficult spots). If people took
the time to help you, at least take the time to Summarise.

Comments

Got something to say?

You must be logged in to post a comment.