AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 513500
Accepted
Tim
Tim
Asked: 2019-04-20 18:15:53 +0800 CST2019-04-20 18:15:53 +0800 CST 2019-04-20 18:15:53 +0800 CST

我们可以在 pdf 文件中搜索包含多个单词且不按特定顺序排列的页面吗?

  • 772

我想在一个 pdf 文件中搜索所有页面,每个页面都包含几个给定的单词,没有特定的顺序。例如,我想查找所有包含“hello”和“world”的页面,没有特定的顺序。

我不确定是否pdfgrep 可以做到。

我正在尝试做一些类似于我们如何在谷歌图书中显示的书中搜索几个单词的事情。

谢谢。

search pdf
  • 2 2 个回答
  • 149 Views

2 个回答

  • Voted
  1. Best Answer
    mosvy
    2019-04-20T18:23:33+08:002019-04-20T18:23:33+08:00

    -P是的,如果您使用该选项(让它使用PCRE引擎和类似 perl 的正则表达式),您可以使用零宽度前瞻断言来做到这一点。

    $ pdfgrep -Pn '(?=.*process)(?=.*preparation)' ~/Str-Cmp.pdf
    8:•     If a preparation process is used, the method used shall be declared.
    10:Standard, preparation may be an important part of the ordering process. See Annex C for some examples of
    38:padding. The preparation processing could move the original numerals (in order of occurrence) to the very
    

    以上仅在两个单词在同一行时才有效;如果单词可以出现在同一页面的不同行上,则可以执行以下操作:

    $ pdfgrep -Pn '^(?s:(?=.*process)(?=.*preparation))' ~/Str-Cmp.pdf
    8:ISO/IEC 14651:2007(E)
    9:                                                                                                  ISO/IEC 14651:2007(E)
    10:ISO/IEC 14651:2007(E)
    12:ISO/IEC 14651:2007(E)
    ...
    

    中的s标志(?s:意味着也.将匹配换行符。请注意,这只会打印页面的第一行;您可以使用以下-A选项进行调整:

    $ pdfgrep -A4 -Pn '^(?s:(?=.*process)(?=.*preparation))' ~/Str-Cmp.pdf
    8:ISO/IEC 14651:2007(E)
    8-•     Any specific internal format for intermediate keys used when comparing, nor for the table used. The use of
    8-      numeric keys is not mandated either.
    8-•     A context-dependent ordering.
    8-•     Any particular preparation of character strings prior to comparison.
    --
    9:                                                                                                  ISO/IEC 14651:2007(E)
    ...
    

    一个粗略的包装脚本,它将以任何顺序从与所有模式匹配的页面中打印与任何模式匹配的行:

    usage: pdfgrepa [options] files ... -- patterns ...

    #! /bin/sh
    r1= r2=
    for a; do
            if [ "$r2" ]; then
                    r1="$r1(?=.*$a)"; r2="$r2|$a"
            else
                    case $a in
                    --)     r2='(?=^--$)';;
                    *)      set -- "$@" "$a";;
                    esac
            fi
            shift
    done
    pdfgrep -A10000 -Pn "(?s:$r1)" "$@" | grep -P --color "$r2"
    

    $ pdfgrepa ~/Str-Cmp.pdf -i -- obtains process preparation 37- the strings after preparation are identical, and the end result (as the user would normally see it) could be 37- collation process applying the same rules. This kind of indeterminacy is undesirable. 37-one obtains after this preparation the following strings:

    • 3
  2. user1133275
    2019-04-20T18:45:25+08:002019-04-20T18:45:25+08:00
    pdfgrep -nP 'hello.{1,99}world|world.{1,99}hello' a.pdf
    

    https://pdfgrep.org/doc.html

    • 1

相关问题

  • pdf文件的页面到变量中

  • 将 pdf 注释合并到单个文件中

  • 文件资源管理器列中的 PDF 元数据

  • 将手册页导出到 postscript

  • 在 Ranger 中预览 PDF 作为图像

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve