Can I grep only the first n lines of a file?

后端 未结 11 1298
后悔当初
后悔当初 2021-01-30 07:33

I have very long log files, is it possible to ask grep to only search the first 10 lines?

11条回答
  •  半阙折子戏
    2021-01-30 08:19

    head -10 log.txt | grep -A 2 -B 2 pattern_to_search
    

    -A 2: print two lines before the pattern.

    -B 2: print two lines after the pattern.

    head -10 log.txt # read the first 10 lines of the file.
    

提交回复
热议问题