10-16-04 02:28 AM
"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote in message news:<2t5lobF1smmp7U1@uni-berli
n.de>...
> On 2004-10-13, usatim wrote:
>
> Why sed?
>
> If you have GNU grep:
>
> grep -A2 "$string" file
>
>
> With awk:
>
> awk "/$string/ {print; getline; print; getline; print; exit}"
>
>
> With the shell:
>
> while IFS= read -r line
> do
> case $line in
> *"$string"*) printf "%s\n" "$line"
> IFS= read -r line
> printf "%s\n" "$line"
> IFS= read -r line
> printf "%s\n" "$line"
> exit
> ;;
> esac
> done < file
>
>
> And if you really want to use sed:
>
> sed -n "/$string/{p;n;p;n;p;q;}" file
Thanks for the response. I was close but I did not have the brackets
and I did not have the last ;.
I know how to find a string and delete it with sed but I have no clue
about how to find string1 and if the next line is string2, delete both
lines, throughout a file. This should be the last time I bother
everyone.
Is there a good sed book I can get. I am not happy with the one I have
(O'Reilly, sed & awk).
[ Post a follow-up to this message ]
|