INFO-UNIX Digest V2#006
Niket K. Patwardhan
bilbo.niket at locus.ucla.edu
Sat Nov 23 03:49:58 AEST 1985
The pattern matching allows you to break up the pattern into parts and replace
specific bits of it in the substitute command. Try this (you may have to escape
stuff if this is on the sed command line)
s/\(#{garbage}\)#/\1/
What this does is bracket the first part of the pattern so you can refer to it
later: (the \(\) does this). Then when you are doing the replacement you ask
for only the first part rather than the whole thing: ( \1 rather than &). If
you have multiple pieces you bracket the pieces you want to refer to, and you
refer to the pieces by counting the number of \( starting from the left. Eg.
s/ \(\(xyz\)abc\(pqr\)\) / \1\2\3/
on
xyzabcpqrxxx
results in
xyzabcpqrxyzpqrxxx
\1 is xyzabcpqr
\2 is xyz
\3 is pqr
If the trailing # is at the end of the line just use
s/#$//
Good luck!
More information about the Comp.unix
mailing list