Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Word Counter - Count words and characters in text Pick of the Week
Word Counter imageThe macosxhints Rating:
9 of 10
[Score: 9 out of 10]
This week's Pick is a niche selection, but I find it quite useful, and maybe others will as well. I will mention, however, that the author has some other interesting apps on his site, so it might be worth a visit to see what else he's got...

In my job, I obviously have to write a lot. But much of the time, I have to write much less -- as in "Rob, we only have 500 words for this blurb, and you've given me 10,250; you'll have to cut it back a bit." Yes, word counts play a crucial role in what we write, as there's only so much space in the magazine each month. While writing in Word, obviously, there's a handy word count feature that I rely on. But there are times when I want to go back and look at something I've written in the past to get an idea of its length. During lunch hour today, for instance, I was writing a strange little blurb for my robservatory.com blog, and needed to get a word count for the entire Panther tips book.

The book exists in 18 separate Word files, one per chapter, as well as 18 'ready to print' PDFs. Counting the book's total words in Word is a chore--you have to open each file and run the word count command, then manually add all the pieces together. (I didn't think I could do anything with the PDFs, so I just ignored them.)

I figured there had to be a better way, so I went searching, and stumbled on Word Counter. The program can read many forms of text, including pure text and (most usefully to me) Word documents; it won't, however, work with PDFs. Using the program couldn't be much simpler -- you can drag and drop a readable file into its window, paste some text from the clipboard, or (my intended use), drag a folder full of files onto it. When you use either of the first two methods, everything happens in one window, and you just click a Count Words button to see the total characters and words in your selected text.

But when you drop a folder or multiple files onto the window, you get a new window that shows the program's progress through all readable files, along with a running word and character count. Depending on the speed of your machine and the number and size of dropped files, this could take a while to run. As a baseline point, processing all 18 files from the book, which consists of nearly 1,000,000 characters and 174,907 words, took about 45 seconds on my Dual 2.0 G5.

Note that if you're going to use this tool, you should read the page on the author's site about it -- he explains some differences in counts returned by his program versus those returned by Word, for instance.

You may not have a need for such a tool very often, but if you ever do, take a look at Word Counter. It does its job quite well.
    •    
  • Currently 1.56 / 5
  You rated: 3 / 5 (9 votes cast)
 
[34,715 views]  

Word Counter - Count words and characters in text | 13 comments | Create New Account
Click here to return to the 'Word Counter - Count words and characters in text' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Word Counter - Count words and characters in text
Authored by: dvandetta on Nov 29, '05 02:33:45PM

If you're using Mac OS X, can't you just use the "wc" command in the Terminal. This should tell you the number of words, lines and characters.

Type

wc <filename> -w (words) -c (characters -l (lines)

I think you can also use this for directories, but I might be wrong...

-Dylan



[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: jriskin on Nov 29, '05 03:32:47PM

Or just...

1. Double click Terminal
2. wc <return>
3. <paste>
4. <ctl-d> (when done)

Output is words, lines, and bytes.

Someone should do a general simple unix command hint...



[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: robg on Nov 29, '05 05:01:31PM
We have hints on wc. But wc doesn't work well on .doc files, at least in my experience. For instance, consider my Chapter 14.doc file...
  • According to Word, it's 47,037 total characters (non-blank) and 9,415 words.
  • Word Counter totals it out to 45,553 characters and 7,742 words. Not exact, but close enough.
  • wc -mw returns two numbers: 49701 and 822272, just like that. No column heading, no commas, which makes reading a bit tougher. But if I'm reading it right, it's telling me that there are 49,701 words and 822,272 characters in that file. Clearly that's not correct.
When I ran wc -wc *.doc on the whole book, it told me that there were 4.3million characters in the files. Word Counter returns a much more accurate figure of just under 1.0million.

So explain to me what I'm doing wrong?

-rob.

[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: daeley on Nov 29, '05 08:47:51PM
You can use the textutil CLI program along with wc to get an accurate wordcount. Here's the command:

textutil -stdout -convert txt foobar.doc | wc -w

To break it down, we're telling textutil to send its output to standard output instead of a file (-stdout) and convert to plain text (-convert txt) a Word formatted file called foobar.doc. The output of that is sent/piped to wc where we ask for a simple count of just the words (-w).

Now then, if you have multiple files, you can combine them on the fly and produce a collective word count thusly:

textutil -stdout -cat txt *.doc | wc -w

The new flag -cat tells it to concatenate all of the .doc files in the working directory.

By the way, the commands above leave the original documents untouched.

[ Reply to This | # ]

Word Counter - Count words and characters in text
Authored by: robg on Nov 29, '05 09:56:29PM

I appreciate the CLI solution ... but in this case, I think I'm going to have to say the GUI is somewhat easier and quicker for me -- especially since a given folder may hold much more than just the files I wish to count. So it's a quick drag-n-drop and that's it ... nice to know, though, that I can do this via SSH if the need arises!

Thanks;
-rob.



[ Reply to This | # ]
using textedit or antiword to convert .doc to ascii
Authored by: zojas on Dec 02, '05 04:08:28PM
another thing to try is 'antiword'. it's a Free program which will convert word files to ascii text (even the tables usually come out decent). it would be interesting to compare antiword to textedit's output.

[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: timbos on Nov 30, '05 04:12:30PM
When I ran wc -wc *.doc on the whole book, it told me that there were 4.3million characters in the files. Word Counter returns a much more accurate figure of just under 1.0million. So explain to me what I'm doing wrong?
Probably nothing. Word generates a heap of text in the files that aren't displayed. Do you use the versioning facility, or track changes? They tend to make the filesizes huge. Also, if you open the docs up in a text editor, you'll probably find lots of extra stuff (like your address etc. all stored in there too!)

[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: zojas on Dec 02, '05 04:10:06PM

.doc files are most assuredly not ascii, which is what wc is assuming.



[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: EddEdmondson on Nov 30, '05 01:58:11AM

Rather than pasting, after copying the text you can just do 'pbpaste | wc -w'



[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: kalderon on Nov 29, '05 05:35:13PM

To determine the word count of a PDF use ps2ascii together with wc like this:

ps2ascii myfile.pdf | wc -w

You can use this method to determine the word count of binary files such as Word documents by printing them as PDFs



[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: GlowingApple on Nov 29, '05 09:14:52PM

Unfortunately it doesn't seem that this command comes standard in OS X. From some Googling it looks like it comes with some TeX or LaTeX package. Does anyone know where I could download this program separately, or at least which TeX package I need to get this program?

Thanks!

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: zpjet on Nov 29, '05 08:39:33PM
the best service ever, WordService, does the job among many other things, and does it well.
Characters:	76
Spaces:		15
Total:		91

Words:		16
Lines:		1


[ Reply to This | # ]
Word Counter - Count words and characters in text
Authored by: adrianm on Dec 01, '05 06:10:28AM

But does it work across lots of files at once? Hard to tell from a cursory glance at the website. I think that was the point of the hint; getting a word count across lots of seperate files.



[ Reply to This | # ]