I wonder how does wc
work? Most times it seems to return the number of lines, but sometimes it seems to be newlines? In the man page its newlines. But:
[jiewmeng@JM textFiles]$ echo -e "\n\n" | wc -
3 0 3 -
If the above returns the number of newlines, it should just return 2? Also I got this wierd file:
[jiewmeng@JM textFiles]$ cat testA.txt
The quick
brown fox
jumped over
the lazy
dog.[jiewmeng@JM textFiles]$ wc testA.txt
4 9 50 testA.txt
In the above case, it appears to be returning the number of newlines?
Best Answer
In your first example echo will add it's newline at the end, you can stop this by adding the -n option to echo.
wc counts characters, words and lines, lines are defined as zero or more characters ending in line feed (
\n
).