I'm using bash under Ubuntu.
Currently this works well for the current directory:
catdoc *.doc | grep "specificword"
But I have lots of subdirectories with .doc files.
How can I search for, let's say, "specificword" recursively?
I'm using bash under Ubuntu.
Currently this works well for the current directory:
catdoc *.doc | grep "specificword"
But I have lots of subdirectories with .doc files.
How can I search for, let's say, "specificword" recursively?
Use find
for recursive searches:
find -name '*.doc' -exec catdoc {} + | grep "specificword"
This will also output the file name:
find -name '*.doc' | while read -r file; do
catdoc "$file" | grep -H --label="$file" "specificword"
done
(Normally I would use find ... -print0 | while read -rd "" file
, but there's maybe a .0001% chance that it would be necessary, so I stopped caring.)
find -name \*.doc -exec sh -c "catdoc '{}' | grep -q 'specificword' && echo {}" \;
Aug 31, 2011 at 14:20
You might want to look at recoll which is a full-text search tool for Linux and Unix systems supporting many different document formats. However, it is index-based, i.e., it has to index the documents you want to search in before the actual search. (Thanks to pabouk for pointing this out).
There is a GUI and a command line, too.
See the documentation for further infos.
Grep should find binary matches with:
find /path/to/dir -name '*.doc' exec grep -l "specificword" {} \;