All my previous posts were related to the Windows-based word count software, but I thought that it is pretty unfair to forget about millions of UNIX users, so today we have a UNIX word count session.
Of course, my UNIX experience is not that huge (it was all about testing a Fedora core under virtual machine), so below you will find mostly the reprints of the word count tips published in other Internet-media.
“wc” (short for word count) is a command in Unix-like operating systems. The program reads either standard input or a list of files and generates one or more of the following statistics: number of bytes, number of words, and number of lines (specifically, the number of newline characters). If a list of files is provided, both individual files and total statistics follow.
This is how to use the “wc” command:
• wc -l print the line count
• wc -c print the byte count
• wc -m print the character count
• wc -L print the length of the longest line
• wc -w print the word count
Well, taking into consideration the languages that don’t use space mark, the byte count will be very much appreciated by users from China, Japan, and Thailand.
After user Gburg inquired how to execute a loop to count each word in a file individually, without using the wc command, the following reply followed:
You can use the script below if your words are space-separated.
#!/bin/ksh
typeset -i I=0
{ while read line
do
for wort in `echo $line`
do
I=$I+1
done
done } < $1
echo $I
Many thanks to user Frank from everybody, except users from China, Japan and Thailand, for whom the script there should be another script 🙂
That’s basically all for UNIX word count today.
P.S. Fans of the open source platforms will definitely like this video. Even such a Windows guy as me liked the trick 🙂