Having trouble finding a word in multiple files

Ralf Mardorf kde.lists at yahoo.com
Sun Jun 14 09:54:37 UTC 2020


On Sun, 2020-06-14 at 05:17 -0400, Pat Brown wrote:
> Unfortunately, none of those suggestions worked. Perhaps it's because
> the files I'm searching are either .doc, .docx  or .odt files.

You first need to decode those files. Btw. even plain text mailbox files
could be e.g. base64 encoded.

To get readable strings even from a binary file you could use the
'strings' command. However, 'strings' doesn't help with e.g. odt or pdf
files.

$ echo "CC BY-SA 3.0 DE  Approved for Free Cultural Works" > /tmp/test.txt
$ strings /tmp/test.txt | grep -e"CC BY-SA 3.0 DE" -e"Approved for Free Cultural Works"
CC BY-SA 3.0 DE  Approved for Free Cultural Works

Since I'm the author, I know for sure that those files contain "CC BY-SA 
3.0 DE" as well as "Approved for Free Cultural Works", but the files
don't contain it as a readable string:

$ strings Documents/Pop-Rock-Buch.odt | grep -e"CC BY-SA 3.0 DE" -e"Approved for Free Cultural Works"
$ strings Documents/Pop-Rock-Buch.pdf | grep -e"CC BY-SA 3.0 DE" -e"Approved for Free Cultural Works"
$

'grep' can only be used to find an expression in text files. odt and
similar formats aren't text files.

> The Dropbox folder is at the root of my home directory and it is an actual
> folder that contains multiple folders under it.

That's no problem for 'grep'.

$ man grep | grep -A2 -i "\-\-recursive"
       -r, --recursive
              Read  all  files under each directory, recursively, following symbolic links only if they are on the command line.  Note that if no file operand is given, grep searches the
              working directory.  This is equivalent to the -d recurse option.





More information about the ubuntu-users mailing list