Greg Schafer wrote:
>
> Hi
>
> Using GNU sed, how can I delete the line immediately _above_ the regexp?
Here is the awk way to do it...
$ awk 'NR>1 && !/pattern/ {print s} {s=$0} END {print s}'
> Deleting the line below the regexp is no problem eg:
>
> sed '/regexp/{n;d}' file
>
> I cannot figure this one out.. but surely it's possible? I'm looking for a
> "sed only" solution.
I am wondering why you prefer a cryptic sed solution to a clear and
extensible awk solution. I am no sed expert but this might do it...
$ sed -n '1h;1!{/pattern/h;/pattern/!{x

};${x

}}'
(There may be a way to avoid duplication of the pattern; I don't
bother.)
Janis
> Thanks
> Greg