I've search the web for this but couldn't find the solution I wanted.
I used grep to search for lines having the word one and that works fine.
I want grep to also count the matched lines as well. But I only get the number only.
I tried this but no cigar.
grep -cn 'one' foo
2
Option c is to count and option n is to show lines. But it still shows the count only.
Thus far, this is the only way to do it. Running grep twice :(
grep 'one' foo ; grep 'one' foo | wc -l
one two three
seven one blah
2
Is it possible for grep to show both the matches and the count without repeating the command again?
BTW, I know awk can do this as I've seen in my research. But I want to know if grep can do this. Thanks in advance :)