Solved

Find files that contain a string, and display line counts

Posted on 2014-12-18
3
248 Views
Last Modified: 2015-01-16
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?
0
Comment
Question by:rudy201
  • 2
3 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 40508495
find . -type f -name "P*" | xargs grep -c foo

or

grep -rc P*
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 40508498
In case, I misunderstood your question and you want the total line count in the file, do

grep -rl foo P* | xargs wc -l
0
 
LVL 62

Expert Comment

by:gheist
ID: 40508626
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)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question