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

后端 未结 11 1282
后悔当初
后悔当初 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:39

    You have a few options using programs along with grep. The simplest in my opinion is to use head:

    head -n10 filename | grep ...
    

    head will output the first 10 lines (using the -n option), and then you can pipe that output to grep.

提交回复
热议问题