[NCLUG] sed help ?
Gabriel L. Somlo
somlo at acns.colostate.edu
Sat Mar 1 15:13:27 MST 2003
Hi,
Thanks to all who replied !
>
> cat foo | sed -e '/some pattern/,+1d' > bar
>
Unfortunately, the 'sed' I have on RedHat8.0 doesn't take kindly to
this:
sed: -e expression #1, char 11: Unexpected ','
>
> perl -lnwe '( $skip || /.../ ) && ( $skip = !$skip, 1 ) || print'
>
This actually worked :) However, from looking at the file I'm editing
again, it turns out I need to remove the matching line, the line
immediately before it, and the line immediately after it... This
immediately eliminates any 'streaming' or 'filter' approach... :(
I know, trying to get 'users' to actually tell you what they *really*
want is always the hardest part :) :)
Turns out good old 'ed' is what really does the job:
echo -e "/some_pattern\n-1,+1d\nw" | ed my_file.html > /dev/null 2>&1
It's doing the edit 'in place' instead of streaming, but that's really
OK given that I need to go back and forth inside the file to get what
I want...
Thanks,
Gabriel
More information about the NCLUG
mailing list