How can I find all PDFs from multiple zip files that contain the search term?

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

1 Answer

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like