ben
ben

Reputation: 341

How to use grep to count no of files in which the given string appears atleast once?

Using the command below i could find the total occurrences of the given string in the current directory.

cat * | grep -c 'nike'

In the same way, how to get the total count of files in which the given keyword appears atleast once?

Thanks a bunch

Upvotes: 0

Views: 186

Answers (3)

SteveScm
SteveScm

Reputation: 565

use grep with wc and -l option is for lines.

grep -R "pattern" .|wc -l

Upvotes: 0

unixrules
unixrules

Reputation: 608

grep -l prints only file names

grep -l 'nike' * | wc -l

Upvotes: 1

Paul Tomblin
Paul Tomblin

Reputation: 182782

grep -l Nike * | wc -l

Don't use cat.

Upvotes: 1

Related Questions