Grep for a word, and if found print 10 lines before and 10 lines after the pattern match

后端 未结 5 620
温柔的废话
温柔的废话 2021-01-01 05:32

I am processing a huge file. I want to search for a word in the line and when found I should print 10 lines before and 10 lines after the pattern match. How can I do it in P

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-01 06:11

    Use grep with -C option, easiest solution:

    grep -C 10 'what_to_search' file.txt
    

提交回复
热议问题