Search only first line in awk

Hi ,

I know this is a noob question but I am not able to find a solution .

I have many scripts which are either shell or perl scripts .
I want to count the number of perl scripts . I am searching the first line from all the files

This is my idea

find . -type f -perm -700 | xargs awk 'NR == 1 && /perl/ {print $0}'

This is not giving any output . :wall:

How can I search a pattern only in the first line of several files using awk.

Thanks.

Here is one way of doing it:

find . -name "*.sh" -exec sed -n '/perl/p;2q' {} \; | wc -l

Any idea using awk ?

I am sure there are several ways of doing this like one of yours, but I am looking for an awk solution (learning pupose)

Thanks.
D

Yes, use this one:

... |
  awk 'FNR == 1 && /perl/'

If you have GNU awk:

... |
  awk 'FNR == 1 && /perl / { print; nextfile }'
1 Like

@raduolov : Worked , exactly I was looking for this .

Thanks.