Take the 2-minute tour ×

Is there a way to count the occurrence of a certain word in document and PDF files? A solution which works on Windows will be most helpful.

I need to use it with various languages.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted


In the terminal:

  • pdftotext YOUR_PDF.pdf YOUR_PDF.txt

  • grep -ci 'word' YOUR_PDF.txt


One-liner : pdftotext YOUR_PDF.pdf - | grep -ci 'word'

share|improve this answer
It can't be used for anything other English can it? –  Oxwivi Mar 16 '11 at 14:30
I can't see why not. Did you try? –  mount.cifs Mar 16 '11 at 16:43
No, then I will and get back at you. Furthermore, having to convert the PDF document into a text files makes me doubt about that the words will remain right... Well, won't know for sure until I try... –  Oxwivi Mar 16 '11 at 17:09
The grep -c option only counts lines, not words. (For example, try echo hi hi | grep -c hi; it only says "1".) As a work-around, split up the words on spaces: echo hi hi | sed -e 's/ /\n/g' | grep -c hi –  Kees Cook Mar 17 '11 at 7:07
Didn't known that. Nice solution, thanks! –  mount.cifs Mar 17 '11 at 8:09
add comment

Your Answer


