Linux – How to count the number of lines matching a pattern returned from a linux command

command-line-interfacegreplinux

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

Best Answer

cat | grep ^foo | wc -l

TO show how many lines containing foo are there.