Frage

i have some pdf files in a folder, by using the following command i can able to get the filename and line which contains the matched word.

pdftotext "sample.pdf" - | grep "search-word" 

but this is working only for a single pdf file, i want to get all the file names in a folder which contains search-word in their content.i don't want to display the matched lines, please suggest me. Thanks

War es hilfreich?

Lösung

The following should list the files matching the pattern:

for i in `find . -type f -name "*.pdf"`; do
  pdftotext "${i}" - | grep -lq "search-word" && echo $i;
done

The -q option for grep prevents any output to STDOUT. -l lists matching files.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top