Given:
- Name and Location of Zip-File. Example: collectionOfPdfFiles2017.zip
- Zip File is a collection of PDFs without folder structure
- Name of PDF File in Zip-File. Example: someFileFrom2017.pdf
Wanted:
- Console way of extracting the named PDF from the given zip file
- The file should be unmodified.
- Basically the extracted file should be in the same condition as I would get it by extracting the whole archive and copying the wanted file by hand.
- Ideally into a destination folder. But that is luxury.
How do I do this? Currently I have a script that will search for strings in PDF files insides ZIPs and prints out the name of the zip and the pdf inside it. I'll post this for good messure:
#!/bin/bash
echo "Hi I'll find text in pdf files that are stored inside zip files."
echo ""
echo "Enter search string:"
read searchString
echo "Ok. I'll search all zip files for content with this text..."
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 $searchString && echo "$z -> $f" # And finally grep the text
done
done
This script was created thanks to this answer.