Linux wc command
How can i count characters, words and lines from a file with wc command?
Lines: wc -l filename.txt
Characters: wc -m filename.txt
Words: wc -w filename.txt
http://www.computerhope.com/unix/uwc.htm
Wc command prints newline, word, and byte counts for each FILE, and a total line, if more than one FILE is specified.
Syntax
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
Option
-c:- print the byte counts
-m:- print the character counts
-l:- print the newline counts
-L:- print the length of the longest line
-W:- print the word counts
–help:- Print help
–version:- Display version information
You can use wc command as shown below to get the required information.
Use -m option to get the Character count
wc -m test_file.txt
-w option to print words count
wc -w test_file.txt
-l option to print newline count
wc -l test_file.txt
Note:- wc works on “/n” lines character. It counts the newline not the number of lines. The count will be one less is there is no newline character. Refer Why does wc -l tell me that this non-empty file has 0 lines?
I hope I answered your question.