如何搜索多个pdf文件的内容? [英] How to search contents of multiple pdf files?
问题描述
如何在目录/子目录中搜索PDF文件的内容?我正在寻找一些命令行工具。似乎 grep
无法搜索PDF文件。
How could I search the contents of PDF files in a directory/subdirectory? I am looking for some command line tools. It seems that grep
can't search PDF files.
推荐答案
您的分发应该提供一个名为 pdftotext
的实用程序:
Your distribution should provide a utility called pdftotext
:
find /path -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "your pattern"' \;
- 是必须将pdftotext输出到stdout,而不是文件。
- 文件名
和 - label =
选项将文件名放在输出的grep。
可选的 - 颜色
标志很好,并告诉grep使用终端上的颜色输出。
The "-" is necessary to have pdftotext output to stdout, not to files.
The --with-filename
and --label=
options will put the file name in the output of grep.
The optional --color
flag is nice and tells grep to output using colors on the terminal.
(在Ubuntu中, pdftotext
由软件包 xpdf-utils
或 poppler-utils提供
。
(In Ubuntu, pdftotext
is provided by the package xpdf-utils
or poppler-utils
.)
此方法使用 pdftotext
和 grep如果要使用GNU
的优势超过 grep
的功能, pdfgrep
code> pdfgrep 不支持。 注意:pdfgrep-1.3.x支持打印上下文行的 -C
选项。
This method, using pdftotext
and grep
, has an advantage over pdfgrep
if you want to use features of GNU grep
that pdfgrep
doesn't support. Note: pdfgrep-1.3.x supports -C
option for printing line of context.
这篇关于如何搜索多个pdf文件的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!