W O R D C O U N T ? A N Y C O U N T !
Dive into Translator's Cyber Monday right away! Win a discount from 25% to 90%.

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.

Word count using the “wc” command (taken from Wiki)

“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 file 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 longest line
• wc -w print the word count

Well, taking into consideration the languages that don’t use space mark, byte count will be very much appreciated by users from China, Japan and Thailand.

Word count without using the “wc” command

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 seperated.

#!/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 🙂

No Comments

Leave a Comment

Time limit is exhausted. Please reload CAPTCHA.

Let's stay in touch!
Subscribe to our Anycount Newsletter to receive great news, tips and unique offers.
* required

© 2019 Advanced International Translations. All rights reserved.