How can I count the number of lines matching a pattern returned from a linux command
I want the number of lines returned beginning with 'foo' , so if I pipe the output to grep will this work?
cat | grep -c ^foo
How can I count the number of lines matching a pattern returned from a linux command
I want the number of lines returned beginning with 'foo' , so if I pipe the output to grep will this work?
cat | grep -c ^foo
cat | grep ^foo | wc -l
TO show how many lines containing foo are there.
From grep man page:
****General Output Control****
-c, --count Suppress normal output;
instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines. (-c is specified by POSIX.)