2

Given:

  • A directory with 1..n ZIP files of random names (all ending with .zip)
    • Each zip file contains 1..n PDF files of random names (all ending with .pdf)
    • All PDFs are from the same source and are to some extend comparable formatted.
    • The PDFs are no prosa text but rather invoices, inventory lists etc. (aka forms and tables; The PDFs are searchable when I open them in an PDF viewer.)
  • A search term i.e. a stock item number or a invoice number

Wanted:

  • A way to find/list all the PDFs that contain the given search term.
  • preferably with existing linux tools.
2
  • Do the PDFs have text or images of invoices?
    – muru
    Oct 11, 2017 at 5:39
  • They have text. (The PDFs are searchable when I open them in an PDF viewer) added this to the description.
    – KFleischer
    Oct 12, 2017 at 5:09

1 Answer 1

1

You can convert the PDF to text and then apply grep on that text:

#!/bin/bash
for z in *.zip
do
  zipinfo -1 "$z" |  # Get the list of filenames in the zip file
    while IFS= read -r f
    do
      unzip -p "$z" "$f" | # Extract each PDF to standard output instead of a file
        pdftotext - - | # Then convert it to text, reading from stdin, writing to stdout
        grep -q 1234 && echo "$z -> $f" # And finally grep the text
    done
done
0

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.