0

I need help to solve a situation. It's seems rather simple, but it's not I guess.

#!/bin/bash

pdfgrep -Hn $1 *.pdf

exit 0

If I run this code in any directory containing ocr'd PDF-files it will spit out "matching file+page number in that file+matching line for the pattern $1".

Now to the problem. Say I want to do the same thing with 2 patterns "$1" and "$2". It will not be as easy as

pdfgrep -Hn $1 | pdfgrep -Hn $2 *.pdf

How could this be done, so that the result will be "matching file+page number in that file containing both patterns $1 and $2"?

Any help appreciated:-)

Thank you!

/Paul

1 Answer 1

0

I found a working solution that's quite simple:

#!/bin/bash

pdfgrep -Hn $1 *.pdf | cut -f1,2 -d':' > /tmp/sok1.tmp
pdfgrep -Hn $2 *.pdf | cut -f1,2 -d':' > /tmp/sok2.tmp
comm -1 -2 --nocheck-order /tmp/sok1.tmp /tmp/sok2.tmp

exit 0

/Paul

2
  • Correction: "comm -2 --nocheck-order /tmp/sok1.tmp /tmp/sok2.tmp" Sep 9, 2016 at 11:59
  • Correction2: For some reason this "comm" is not consistant. So then I changed last line to : "grep -f /tmp/sok1.tmp /tmp/sok2.tmp" and it worked!!! Sep 9, 2016 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.