Reputation: 2616
Question: How can I get all the files with name "interesting-file.txt" that have more than one line in them?
Background research:
find . -name "interesting-file.txt"
wc -l
to get their line
number.awk '$1 > 1'
to find those files with
more than one line.But I'm having problems putting it all together.
I've tried a few variations of
find . -name "interesting-file.txt" | awk '{print wc -l $0}'
with no success. I haven't started on the "greater than one" other than to look for the related command.
I'm on OSX, using the standard terminal.
Thanks for any help!
Upvotes: 6
Views: 4093
Reputation: 74645
I would go for something like this:
find . -name "interesting-file.txt" -exec awk 'END { if (NR > 1) print FILENAME }' {} \;
All the files that are found are passed to awk, which prints the name if the number of lines NR
is greater than 1.
With GNU awk you can take advantage of the ENDFILE
block and use {} +
to minimise the number of invocations of awk:
find . -name "interesting-file.txt" -exec awk 'ENDFILE { if (FNR > 1) print FILENAME }' {} +
Upvotes: 13