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

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

    The output of head -10 file can be piped to grep in order to accomplish this:

    head -10 file | grep …
    

    Using Perl:

    perl -ne 'last if $. > 10; print if /pattern/' file
    

提交回复
热议问题