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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top