How can I make 'grep' show a single line five lines above the grepped line?

后端 未结 4 1022
广开言路
广开言路 2020-12-30 19:57

I\'ve seen some examples of grepping lines before and after, but I\'d like to ignore the middle lines. So, I\'d like the line five lines before, but nothing else. Can this b

4条回答
  •  梦谈多话
    2020-12-30 20:42

    This way is easier for me:

    grep --no-group-separator -B5 "pattern" file | sed -n 1~5p
    

    This greps 5 lines before and including the pattern, turns off the --- group separator, then prints every 5th line.

提交回复
热议问题