4

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.

1 Answer 1

6

PDF:

In the terminal:

  • pdftotext YOUR_PDF.pdf YOUR_PDF.txt

  • grep -ci 'word' YOUR_PDF.txt

Edit:

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

4
  • It can't be used for anything other English can it?
    – Oxwivi
    Mar 16, 2011 at 14:30
  • I can't see why not. Did you try?
    – mount.cifs
    Mar 16, 2011 at 16:43
  • 1
    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, 2011 at 17:09
  • 3
    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, 2011 at 7:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .