/usr/local/bin にある #!/usr/bin/python3
をみつけたい、場面です。
こんな感じ。
find /usr/local/bin -type file | xargs awk '/python3/ {print FILENAME} {nextfile}'
1行目だけ検査したらさっさと nextfile
で次に移るので OK というわけ。
nextfile Stop processing the current input file. The next input record read comes from the next input file. FILENAME and ARGIND are updated, FNR is reset to 1, and processing starts over with the first pattern in the AWK program. If the end of the input data is reached, the END block(s), if any, are executed.
追記
FNR
(行番号)を if で判定して nextfile
することで、任意の行数を処理できます。
あと、grep といいつつ awk なタイトル詐欺ですみません。