I have a file called “email.txt” and I want to count the number of lines in it.
cat email.txt | wc -l
cat email.txt | sed -n '$='
The first example uses wc (which stands for “what’s the count”) with the -l (lines only) optin. The contents is pushed via cat through standard output into a pipe and thusly becomes standard input for the next command (wc).
The second example does the same thing with sed, and demonstrates a number of interesting aspects of sed. the equal sign causes the output of the current line number. Sed normally runs through all the lines of the file or input given to it. So this one liner would print the line number for each line of email text. However, the -n option causes sed to repress automatic printing unless specifically requested.




