Yes, you can do it with zero-width lookahead assertions, if you use the -P
option (which let it use the PCRE
engine and perl-like regexps).
$ 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
The above will only works if the two words are on the same line; if the words can occur on separate lines of the same page, the following will do:
$ 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)
...
The s
flag in (?s:
means that .
will also match a newline. Notice that that will only print the first line of the page; you can adjust that with the -A
option:
$ 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)
...
A crude wrapper script that will print the lines matching any of the patterns from the pages matching all of the patterns in any order:
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: