wc – print newline, word, and byte counts for each file

In this article, let’s see wc Unix command. This Unix command is used to print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified.

wc syntax

wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F

Options Example

Let see examples for each command option.

no option
$ wc wc_demo.txt
1 4 20 wc_demo.txt

when no option is specified wc prints above output line count word count byte count as 1 4 20 respectively.

-c — bytes

print the byte counts

$ wc -c wc_demo.txt
20 wc_demo.txt
-m  –chars

print the character counts

$ wc -m wc_demo.txt
20 wc_demo.txt
-l –lines

print the newline counts

$ wc -l wc_demo.txt
1 wc_demo.txt

 

Note: wc works on /n lines character. If there is no line character at the end of file, count will be one less. Check this thread on StackOverflow The wc -l gives wrong result

-L, –max-line length

print the length of the longest line

wc -L wc_demo.txt
19 wc_demo.txt
-w, –words

print the word counts

$ wc -w wc_demo.txt
4 wc_demo.txt
–help

display this help and exit

–version

output version information and exit





Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *