Данный:
Требуемый:
Как я делаю это? В настоящее время у меня есть сценарий, который будет искать строки во внутренностях файлов PDF, АРХИВИРУЕТ и распечатывает название zip и PDF в нем. Я отправлю это для хорошего 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
Этот сценарий был создан благодаря этому ответу.
расстегните молнию на определенном файле от zip-архива
unzip -j "myarchive.zip" "in/archive/file.pdf" -d "/destination/path/"
В Вашем сценарии
# Set a destination path
dest="/path/to/unzip/to"
# dump pdf to temp text file
tempfile=$(mktemp)
# unzip the file to stdOut and convert it to text
unzip -p "$z" "$f" | pdftotext - $tempfile
if grep -q $searchString $tempfile; then
unzip -j "$z" "$f" -d "$dest"
# some text output
echo "$z -> $f"
fi
rm $tempfile