Reputation: 2162
For example:
cat /etc/passwd
What is the easiest way to count and display the number of lines the command outputs?
Upvotes: 1
Views: 4577
Reputation: 35395
wc
is the unix utility which counts characters, words, lines etc. Try man wc
to learn more about it. The -l
option makes it print only the number of lines (and not characters and other stuff).
So, wc -l <filename>
will print the number of lines in the file <filename>
.
You asked about how to count number of lines output from a command line program in general. To do that, you can use pipes in unix. So, you can pipe the output of any command to wc -l
. In your example, cat /etc/password
is the command line program you want to count. For that you should do:
cat /etc/password | wc -l
Upvotes: 7