I have the similar problem with OpenDocument (ODT document, OTT template) and Microsoft Word (DOC and DOCX documents, DOT and DOTX templates) files.
Currently, I'm happy with the following Bash script for recursive search:
#!/bin/sh
if [ "$#" -ne 1 ]; then
echo $"Usage: $(basename "$0") search_pattern"
echo "You should have installed the following packages: odt2txt, docx2txt and libreoffice-writer"
exit 1
fi
search_pattern="$1"
printf "Looking for: $search_pattern\n"
find . -name '*.odt' -o -name '*.ott' -o \
-name '*.docx' -o -name '*.dotx' -o \
-name '*.doc' -o -name '*.dot' \
-type f | while read -r doc; do
doc_fullfilename=$(basename -- "$doc")
doc_filename="${doc_fullfilename%.*}"
doc_filetype="${doc_fullfilename##*.}"
case $doc_filetype in
'odt' | 'ott')
(odt2txt "$doc" 2>/dev/null | grep -i "$search_pattern") && echo "^ found in ODT/OTT: $doc" && echo
;;
'docx' | 'dotx')
(docx2txt "$doc" - 2>/dev/null | grep -i "$search_pattern") && echo "^ found in DOCX/DOTX: $doc" && echo
;;
'doc'| 'dot')
out_dir=/tmp
lowriter --headless --convert-to txt:Text "$doc" --outdir "$out_dir" 2>&1 > /dev/null
grep -i "$search_pattern" "$out_dir/$doc_filename.txt" && echo "^ found in DOC/DOT: $doc" && echo
;;
esac
: ; done
It shows search results and file-names.
Notes:
- the script uses three external programs -
odt2txt
(for ODT/OTT), docx2txt
(for DOCX/DOTX), libreoffice-writer
(for DOC/DOT).
- theoretically, all these programs may be changed to only one - LibreOffice Writer, but it significantly slower for ODT/OTT and DOCX/DOTX.
qt
dependencies.