How to strip A NEWLINE
Philippe Deschamp
deschamp at minos.inria.fr
Sat Dec 1 04:25:01 AEST 1990
In article <25665 at uflorida.cis.ufl.EDU>, bjs at reef.cis.ufl.edu (Brian J. Smith)
writes:
|> I have searched high and low for the answer on how to strip a NEWLINE
|> charactor from a file. Well not really a NEWLINE char, but a ":\\\n"
|> (colon,back-slash,newline). I have tried useing sed with:
|>
|> sed 's/:\\\n//' file
|>
|> and using the RS variable in awk, but to no avail. sed will remove
|> the colon and the back-slash, but not the newline.
The key is that "\n Matches a NEWLINE embedded in the pattern space." (from
sed(1)). So you must embed a NL in the pattern space! With the "N" command,
for example. The following does what you asked for, I should think:
sed -e ': more
/:\\$/{
N
s/:\\\n *:*/:/
t more
}'
You can read this as
while the current line ends with ":\", do
append next line to current, with NL in between,
get rid of "\", the NL and some TABs and superfluous ":"s
end while
Have fun! Sed is a wonderful tool, as long as you don't overuse it...
Philippe Deschamp.
Tlx: 697033F Fax: +33 (1) 39-63-53-30 Tel: +33 (1) 39-63-58-58
Email: Philippe.Deschamp at nuri.inria.fr || ...!inria!deschamp
Smail: INRIA, Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France
More information about the Comp.unix.shell
mailing list