LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Search for a word in multiple ODT files (https://www.linuxquestions.org/questions/linux-software-2/search-for-a-word-in-multiple-odt-files-4175579417/)

NotAComputerGuy 05-10-2016 07:43 AM

Search for a word in multiple ODT files
 
Hi,

I'm trying to find specific words within multiple documents. All the answers so far result in nothing. Does anyone know a way I can search the contents of a folder containing multiple odt files for a specific word please?

I'm using LMDE and Libre office 1:4.3.3-2+deb8u3

Thanks

HMW 05-10-2016 07:53 AM

Quote:

Originally Posted by NotAComputerGuy (Post 5543156)
Does anyone know a way I can search the contents of a folder containing multiple odt files for a specific word please

Yes:
http://ubuntuforums.org/showthread.p...06#post5859706
http://www.linuxquestions.org/questi...es-4175511386/
http://superuser.com/questions/68220...ep-not-working

DuckDuckGo is your friend...

Best regards,
HMW

NotAComputerGuy 05-10-2016 08:37 AM

The first link I've tried and none of the results listed return anything. I search for the word "the" which occurs multiple times in multiple documents and it displays nothing.

The second link states "ODT files are ZIP files containing a structure of files and directories. You can unzip them. The text is in xml format in content.xml." but I've got no idea how I would unzip multiple files and then search them all for a word. It seems unlikely that it's possible in my extremely limited knowledge. A single file I could achieve but multiple files seems unlikely.

The third results in:
caution: filename not matched: /home/user/path/to/documents/doc1.odt
caution: filename not matched: /home/user/path/to/documents/doc2.odt
caution: filename not matched: /home/user/path/to/documents/doc3.odt
/usr/bin/zipgrep: 97: test: -eq: unexpected operator
/usr/bin/zipgrep: 100: test: Illegal number:


Thanks for trying though. You say you know how it can be done, could you tell me directly please? :)

NotAComputerGuy 05-10-2016 08:54 AM

People who come across this thread in future.

I found

Code:

for file in *.odt; do    unzip -c "$file" | grep -iq insertsearchtexthere && echo "$file"; done
to be the answer assuming all the files are in one directory.


That was found here: https://superuser.com/questions/6822...ep-not-working

keefaz 05-10-2016 10:28 AM

Code:

zgrep -i -l insertsearchtexthere *.odt
No?
[edit]
Ah ok, zgrep is for gziped files...

HMW 05-10-2016 12:08 PM

Quote:

Originally Posted by NotAComputerGuy (Post 5543191)
Thanks for trying though. You say you know how it can be done, could you tell me directly please? :)

You solved it yourself :thumbsup: Awesome!

Best regards,
HMW

HMW 05-10-2016 12:26 PM

Quote:

Originally Posted by NotAComputerGuy (Post 5543191)
The first link I've tried and none of the results listed return anything. I search for the word "the" which occurs multiple times in multiple documents and it displays nothing

But... this is strange.

I tried this solution myself and it works as one could expect. I have an .odt file with this content:
”Document containing keyword foo

End!“

This is located here on my machine
Code:

/home/HMW/Dokument/test.odt
Now, if I run the following (searchodt.sh):
Code:

find $HOME/Dokument -name "*.odt" | while read file
do
        unzip -ca "$file" content.xml | grep -qli "foo"
        if [ $? -eq 0 ]; then
                echo "Found keyword in: " $file
        fi 
done

I get this result:
Code:

./searchodt.sh
Found keyword in:  /home/HMW/Dokument/test.odt

Not that it matters since you have already solved this, but it is odd it didn't work on your end.

Best regards,
HMW


All times are GMT -5. The time now is 07:28 PM.