Counting lines, words, characters in text files with Linux with wc
Written by Guillermo Garron
Date: 2007-04-14 10:36:30 00:00
There are a lot of useful tools in Linux and wc is one of them, this tool let us know the number of:
Lines, words or characters that we could find in a text file, its use is very simple:
Usage
wc [OPTION]… [FILE]…
Where the options are
-c, --bytes
print the byte counts
-m, –chars
print the character counts
-l, --lines
print the newline counts
-L, --max-line-length
print the length of the longest line
-w, --words
print the word counts
For example
Suppose you have a file called mytextfile.txt and would like to know how many lines and words it have just enter:
wc -l -w mytextfile.txt
The output will be like this.
7334 22002 /home/user/mytextfile.txt
So it has 7334 lines and 22002 words.