count number of lines in terminal output

roopunk picture roopunk · Sep 17, 2012 · Viewed 268.2k times · Source

couldn't find this on SO. I ran the following command in the terminal:

>> grep -Rl "curl" ./

and this displays the list of files where the keyword curl occurs. I want to count the number of files. First way I can think of, is to count the number of lines in the output that came in the terminal. How can I do that?

Answer

João Silva picture João Silva · Sep 17, 2012

Pipe the result to wc using the -l (line count) switch:

grep -Rl "curl" ./ | wc -l