首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从有很多pdfs的zip文件中提取特定的pdf。

从有很多pdfs的zip文件中提取特定的pdf。
EN

Ask Ubuntu用户
提问于 2019-12-11 07:46:43
回答 1查看 1.2K关注 0票数 2

给予:

  • 邮编文件的名称和位置。示例:GogtionOfPdfFiles2017.zip
    • Zip文件是一个PDF的集合,没有文件夹结构

  • 压缩文件中PDF文件的名称-文件。示例:omeFileFrom2017.pdf

通缉:

  • 从给定zip文件中提取命名PDF的控制台方法
  • 文件应未修改。
    • 基本上,提取的文件应该与我通过提取整个归档文件并手动复制所需文件的情况相同。

  • 理想情况下进入目标文件夹。但那是奢侈。

我该怎么做?目前,我有一个脚本,将搜索字符串在PDF文件,内部,拉链和打印出来的名字,zip和里面的pdf。我会把这封信寄给你:

代码语言:javascript
复制
    #!/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 

这个脚本是由于这个答案而创建的。

EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2019-12-11 09:48:59

从zip归档解压缩特定文件

代码语言:javascript
复制
unzip -j "myarchive.zip" "in/archive/file.pdf" -d "/destination/path/"

在你的剧本里

代码语言:javascript
复制
# 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
票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1195340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档