If you have already collected the grep
output in a file, you could output a numbered list with:
cat -n myfile
If you only want the number of lines, simply do:
wc -l myfile
There is absolutely no reason to do:
cat myfile | wc -l
...as this needlessly does I/O (the cat
) that wc
has to repeat. Besides, you have two processes where one suffices.
If you want to grep
to your terminal and print a count of the matches at the end, you can do:
grep whatever myfile | tee /dev/tty | wc -l
Note: /dev/tty
is the controlling terminal. From the tty(4)
man page:
The file /dev/tty
is a character file with major number 5 and minor number 0, usually of mode 0666 and owner.group
root.tty
. It is a synonym for the controlling terminal of a process, if any.
In addition to the ioctl(2)
requests supported by the device that tty refers to, the ioctl(2)
request TIOCNOTTY
is supported.