anyway07
anyway07

Reputation: 395

Number of files containing a given string

I want to show text files that contain a string and to count them. My code is:

grep -l "string" file1.txt file2.txt | wc -l

It shows the number of files that contain "string". How can I show the names of the files too?

Upvotes: 2

Views: 85

Answers (1)

oguz ismail
oguz ismail

Reputation: 50815

How about teeing it?

grep -l 'string' file1.txt file2.txt | tee >(wc -l)

Upvotes: 1

Related Questions