Afficher un message
Vieux 02/11/2006, 14h15   #2
Janis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sed line deletion

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


  Réponse avec citation
 
Page generated in 0,05831 seconds with 9 queries