grep - print line before, don't print match

前端 未结 3 997
青春惊慌失措
青春惊慌失措 2020-12-17 21:31

How to easily print line above the match and skip the match itself? grep -A, -B and -o opt do not solve it. Maybe some

3条回答
  •  难免孤独
    2020-12-17 22:22

    Just set p to the pattern you want:

    $ awk '$0~p{print a}{a=$0}' p="foo" file
    bar
    baz
    foo
    

提交回复
热议问题