SED: addressing two lines before match

后端 未结 6 1645
梦如初夏
梦如初夏 2021-01-20 05:20

Print line, which is situated 2 lines before the match(pattern).

I tried next:

sed -n \': loop
/.*/h
:x
{n;n;/cen/p;}
s/./c/p
t x
s/n/c/p
t loop
{g;p         


        
6条回答
  •  醉梦人生
    2021-01-20 06:01

    If you can use awk try this:

    awk  '/pattern/ {print b} {b=a;a=$0}' file
    

    This will print two line before pattern

提交回复
热议问题