rudy201
asked on
Find files that contain a string, and display line counts
I use below to list all P* files that contain "foo"
find . -type f -name "P*" -exec grep -l foo {} \;
How should I change this command to also display line count next to each file name?
find . -type f -name "P*" -exec grep -l foo {} \;
How should I change this command to also display line count next to each file name?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
find basedir1 basedir2 -type f -name P* -print0 | xargs -0 wc -l
(this one starts one wc command for many arguments, a bit more efficient than re-executing for each file)
(this one starts one wc command for many arguments, a bit more efficient than re-executing for each file)
or
grep -rc P*