1

I've searched online and I cannot find the answer I need..I need to search recursively in Linux environment through multiple directories for a file named "monthly_spd.pdf" for a key word phrase such as "MOS-corrected" and then print that row where "MOS-corrected" is found and also print the path/filename.

I've tried this below and I can print or display the file/path name but I have not figured out how to print the row where the key word phrase ("MOS-corrected") is found in each file. Thank you.

 find . -name 'monthly_spd.pdf' -exec echo {} \: -exec pdftotext {} - \; | grep "MOS-corrected, r\|pdf"
user2100039
  • 1,280
  • 2
  • 16
  • 31

2 Answers2

0

I have found an answer here in the link below by adding the "-C5" after "grep" in the solution I tried above for printing the context around the key word phrase, which is exactly what I needed. See remark/comment from Colin D Bennett!

How to search contents of multiple pdf files?

user2100039
  • 1,280
  • 2
  • 16
  • 31
-1

Use:

pdfgrep -HinR 'FWCOSP' DatenModel/

In this command I'm searching for the word FWCOSP inside the folder DatenModel/.

As you can see in the output you can have the file name wit the line numbers:

enter image description here

The options I'm using are:

-i : Ignores, case for matching
-H : print the file name for each match
-n : prefix each match with the number of the page where it is found
-R : same as -r, but it also follows all symlinks.
Francesco Mantovani
  • 10,216
  • 13
  • 73
  • 113