Linux command line has a lot of fun around itself and many tedious task can be performed very easily yet with perfection. Playing with words and characters, their frequency in a text file, etc is what we are going to see in this article.
The only command that comes to our mind, for tweaking Linux command line to manipulate words and characters from a text file is [wc command][1].
![Fun with Word and Letter Counts in Shell](http://www.tecmint.com/wp-content/uploads/2014/03/Linux-Word-Count.png)
A ‘**wc**‘ command which stands for word count is capable of Printing Newline, word & byte counts from a text file.
To work with the small scripts to analyze text file, we must have a text file. To maintain uniformity, we are creating a text file with the output of man command, as described below.
$ man man > man.txt
The above command creates a text file ‘**man.txt**‘ with the content of ‘**manual page**‘ for ‘man‘ command.
We want to check the most common words, in the above created ‘**Text File**‘ by running the below script.
The above one liner simple script shows, ten most frequently appearing words and their frequency of appearance, in the text file.
How about breaking down a word into individual using following command.
$ echo 'tecmint team' | fold -w1
### Sample Output ###
t
e
c
m
i
n
t
t
e
a
m
**Note**: Here, ‘-w1′ is for width.
Now we will be breaking down every single word in a text file, sort the result and get the desired output with the frequency of ten most frequent characters.
$ fold -w1 <man.txt|sort|uniq-c|sort-rn|head
### Sample Output ###
8579
2413 e
1987 a
1875 t
1644 i
1553 n
1522 o
1514 s
1224 r
1021 l
How about getting most frequent characters in the text file with uppercase and lowercase differently along with their occurrence frequency.
1 act as if this option was supplied using the name as a filename
1 activate local mode format and display local manual files
1 acute accent
**Note**: The more and more dots in the above script till all the results are generated. We can use .{10} to get ten character matches.
These simple scripts, also make us know most frequent appearing words and characters in English.
That’s all for now. I’ll be here again with another interesting and off the beat topic worth knowing, which you people will love to read. Don’t forget to provide us with your valuable feedback in comment section, below.