Assuming your using Bash 4, you can do the following:
shopt -s globstar
grep -i GWT **/*.odt
shopt -u globstar
When the shell option globstar is set, ** recursively matches all subdirectories of the current directory. The second shopt command unsets the command; this step is optional.
As @vanthome points out, grepping the ODT files won't do any good, since they're actually compressed. There are two inconveniences:
- The zipgrep command doesn't take more than one archive name as an argument, so you have to loop through all ODT files.
- zipgrep will print the matching line only (which can be very long in an ODT file), so you still won't know which files contain the string.
The following might achieve the desired results:
shopt -s globstar
for file in **/*.odt; do
unzip -c "$file" | grep -iq GWT && echo "$file"
done
shopt -u globstar
The for loop goes through all ODT files in all subdirectories. For each file that is found, it unpacks its contents to STDOUT. Then, grep searches for the desired string without outputting anything (-q
). If a match is found, grep returns 0 and the command after the logical AND (&&
) gets executed, so the filename is echoed on the terminal.
grep -i -r "GWT" \*.odt
Since odt files are not plain text, I'm not really sure of the results accuracy..odt
, not to recurse through all directories and search only files ending with.odt
.find
to solve this.grep
offers some useful options for its recursive search. See--include
,--exclude
, and--exclude-dir
in theman
page. For example:grep -R --include '*.odt' -i 'GWT' *