Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
As you can see i found two files on the Desktop - "TA response.txt" and something in the .exe file
However, I have a couple of .odt files on the Desktop which contain the word "dear". Why are they not found?
(I also can't find .odt files using SerachMonkey or Catfish gui)
Thanks!
grep search only text. Files in the OpenDocument Format are XML, which is text, but they are compressed using the Zip utility. So if you would like to search OpenDocument Format using grep, use unzip in front of it.
Code:
unzip -c filename.odt | grep -a whateverpattern
However, that probably won't be of much use because there are few linebreaks in the XML contained in OpenDocument Format files. I'd say you are better off setting up recoll, it's not that difficult.
Last edited by Turbocapitalist; 10-18-2018 at 11:34 PM.
Reason: missed the -c
Wow. Wikipedia really finally cleaned up all that sabotage of the ODF pages. Ten years ago Microsofters were camping all over that page, doing their best to delete any useful information and fill it with disinformation and redundancies.
Field95 has the basic answer. It can be extended to search several files in one folder and just to give you a list of the files with the sought term, rather than every paragraph containing it.
Code:
for file in path/*.odt; do unzip -c $file | grep -iq searchtext && echo $file; done
The loop takes each .odt file in the folder path. Each is then unzipped and passed to grep. The -q parameter with grep means that it doesn't output anything, but just stops the moment it finds searchtext. If it's successful, the file name is printed by echo.
I confess I didn't invent this one myself, and I'm eternally grateful the the one who did!
Field95 has the basic answer. It can be extended to search several files in one folder and just to give you a list of the files with the sought term, rather than every paragraph containing it.
Code:
for file in path/*.odt; do unzip -c $file | grep -iq searchtext && echo $file; done
The loop takes each .odt file in the folder path. Each is then unzipped and passed to grep. The -q parameter with grep means that it doesn't output anything, but just stops the moment it finds searchtext. If it's successful, the file name is printed by echo.
I confess I didn't invent this one myself, and I'm eternally grateful the the one who did!
One of the few times --label seems useful
Code:
for i in *.odt; do unzip -c "$i" | grep --label="$i" -l "searchtext"; done
I might include a -I to ignore binary files that might crop up when searching multiple files in these odt files
Code:
--label=LABEL
Display input actually coming from standard input as input coming from file LABEL. This is especially useful when implementing tools like zgrep, e.g., gzip -cd foo.gz |
grep --label=foo -H something. See also the -H option.
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.
-I Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.