Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.