My grep
solution as a function you can paste in your .bashrc
docx_search(){ local arg wordfile terms=() root=${root:-/}; for arg; do terms+=(-e "$arg"); done; find 2>/dev/null "${root%/}/" -iname '*.docx' -exec bash -c "$(declare -p terms)"'; for arg; do unzip -p "$arg" 2>/dev/null | grep --quiet --ignore-case --fixed-strings "${terms[@]}" && printf %s\\n "$arg"; done' _ {} +; }
It will look for any (case insensitive) occurence of its arguments and print the matching docx file location.
Examples:
$ docx_search 'my example sentence'
/cygdrive/d/example sentences.docx
/cygdrive/c/Users/my user/Documents/example sentences.docx
$ root='/cygdrive/c/Users/my user/' docx_search 'seldom' 'full sentence'
/cygdrive/c/Users/my user/Documents/example sentences.docx
$
Readable version:
docx_search(){
local arg wordfile terms=() root=${root:-/}
# this 'root' assignment allows you to search in a specific location like /cygdrive/c/ instead of everywhere on the machine
for arg; do terms+=(-e "$arg"); done
# We inject the terms to search inside the string with declare -p`
find 2>/dev/null "${root%/}/" -iname '*.docx' -exec \
bash -c "$(declare -p terms)"';
for arg; do
unzip -p "$arg" 2>/dev/null |
grep --quiet --ignore-case --fixed-strings "${terms[@]}" &&
printf %s\\n "$arg"
done' _ {} +
}