Author : Piyush Gupta
The most easiest way to count the number of lines, words, and characters in text file is to use the Linux command “wc” in terminal.
The most easiest way to count the number of lines, words, and characters in text file is to use the Linux command “wc” in terminal.
The command “wc” basically means “word count” and with different optional parameters one can use it to count the number of lines, words, and characters in a text file.
To count the number of lines, use “wc” with “l” as
To count the number of words, use “wc” with “w” option as
And to count the total number of characters, use “wc” with “c” as
Using wc with no options will get you the counts of bytes, lines, and words (-c, -l and -w option).
Example:
Following command will count number of lines in /etc/passwd files and print on terminal. We can also use –lines in place of -l as command line switch.
Count Total Character in File:
Use -m or –chars switch with wc command to count number of characters in a file and print on screen.
Count Total Words in File:
Use -w or –words switch with wc command to count number of words in a file and print on screen.
No comments:
Post a Comment