特定の順序なしに複数の単語を含むPDFファイルのすべてのページを検索したいと思います。たとえば、「hello」と「world」(特定の順序なし)の両方を含むすべてのページを探したいとします。
pdfgrep
それが可能かどうかはわかりません。
私は、Googleブックスに表示される書籍で複数の単語を検索する方法と同様のことをしようとしています。
ありがとうございます。
ベストアンサー1
-P
はい、PCRE
そのオプションを使用している場合は、幅0の予測アサーションを使用してこれを行うことができます(エンジンと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
上記の方法は、2つの単語が同じ行にある場合にのみ機能します。単語が同じページの別の行に表示される場合は、次の操作を行います。
$ 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: