larry@geowhiz.UUCP (Larry McVoy) (11/20/85)
Seeing as everyone is brushing off their 'sed-wizard' hats, I've a question
too:
[input]
{garbage}#{complete garbage}#{more garbage}
....
[desired output]
{garbage}#{complete garbage}{more garbage}
....
What I want is to find a string delimited by starting and ending '#'s, and
strip off the last '#' (don't ask way, it had something to do with making
a grammer input human-readable). Sed gives me the option of including
the address string in the substitution string, but not part of it. Example:
s/#[^#]*#/&YUCK/g
should give me "#{complete garbage}#YUCK". I've been doing this, then a
s/#YUCK//g
to strip off the trailing '#'. Does anyone have a better solution?
--
Larry McVoy +----------------+
| Slower traffic |
Arpa: mcvoy@rsch.wisc.edu | keep right |
Uucp: {seismo, ihnp4}!uwvax!geowhiz!geophiz!larry +----------------+
vsh@pixdoc.UUCP (Steve Harris) (11/21/85)
> [input] > {garbage}#{complete garbage}#{more garbage} > .... > > [desired output] > {garbage}#{complete garbage}{more garbage} > .... try: s/#\([^#]*\)$/\1/ -- Steve Harris | {allegra|ihnp4|cbosgd|ima|genrad|amd|harvard}\ Pixel Systems Inc. | !wjh12!pixel!pixdoc!vsh 300 Wildwood Street | Woburn, MA 01801 | 617-933-7735 x2314
radzy@calma.UUCP (Tim Radzykewycz) (11/21/85)
In article <294@geowhiz.UUCP> larry@geowhiz.UUCP (Larry McVoy) writes: >[input] >{garbage}#{complete garbage}#{more garbage} >.... >[desired output] >{garbage}#{complete garbage}{more garbage} >.... [has been using:] >sed -e 's/#[^#]*#/&YUCK/g' -e 's/#YUCK//g' Better is: sed -e 's/#\([^#]*\)#/#\1/g' There is a reasonably good description of regular expressions (as used by sed) in the man page for ed. -- Tim (radzy) Radzykewycz, The Incredible Radical Cabbage calma!radzy@ucbvax.ARPA {ucbvax,sun,csd-gould}!calma!radzy