--- layout: page author: Alessandro Luini category-page: advanced category-title: Advanced commands tags: word count lines title: wc --- The program reads either standard input or a list of files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.
wc file1.txt file2.txtwill output:
40 149 947 file1.txt 2294 16638 97724 file2.txt 2334 16787 98671 totalThe first column is the count of newlines, meaning that the text file
file1.txt
has 40 newlines while bar has 2294 newlines-
resulting in a total of 2334 newlines. The second column indicates the
number of words in each text file showing that there are 149 words in file1.txt
and 16638 words in file2.txt
– giving a total of 16787 words.file1.txt
has 947 characters while bar has 97724 characters – 98671
characters all in all.wc -l file1.txtPrints the line count (note that if the last line does not have
\n
,
it will not be counted).
wc -c file1.txtPrints the byte count.
wc -m file1.txtPrints the character count.
wc -L file1.txtPrints the length of longest line (GNU extension)
wc -w file1.txtPrints the word count.