Kasramvd Kasramvd - 1 month ago 4
Bash Question

search a word inside a pdf in terminal linux without any app

Is it possible to use

grep
or other command and/or
regex
in order to search for a particular pattern within a PDF file?

Answer

If you have the pdftotext utility installed, you can use the following command to search through the text of a PDF file:

pdftotext myfile.pdf - | grep 'pattern'

You have to use some utility (such as pdftotext) to convert the PDF file to text before feeding it into grep (otherwise grep would have a hard time making sense out of the raw PDF file), but any utility that does this should work.

On Ubuntu and Debian, pdftotext is part of the poppler-utils package.

Comments