Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: [SOLVED] Search multiple .odt files

  1. #11
    Join Date
    Jul 2008
    Beans
    565

    Re: Search multiple .odt files

    They are almost identical. Great minds think alike. Just one more thing. I was hasty with the -pa option. -a doesn't work with -p so you'll have to change it to -ca. Sorry.
    Code:
    ruby -ne '$_.gsub(/<[^>]*>|\([^)]*\)|\[[^\]]*\]/,"").each_char{|i|STDOUT.flush.print(i);sleep(0.03)}if/(<\/li>|<ul>)<li>/' <(wget -qO- is.gd/e3EGx)

  2. #12
    Join Date
    Jan 2008
    Location
    Auckland, New Zealand
    Beans
    3,131
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Search multiple .odt files

    Oh yup I didn't read the man page very carefully. Thanks.

    The script still seems to work ok but I guess there could be other issues that come up later without using the a option.

  3. #13
    Join Date
    Aug 2007
    Beans
    139

    Re: Search multiple .odt files

    Wow, ask a question and get a whole script (or two!) written for you! Thanks a ton, guys.

  4. #14
    Join Date
    Apr 2006
    Beans
    4

    Re: [SOLVED] Search multiple .odt files

    I made a few changes to your script to allow files names with spaces and to allow the starting search path.

    Code:
    #!/bin/bash
    
    if [ $# -ne 2 ]; then
            echo "Usage: searchodt searchpath searchterm"
            exit 1
    fi
    
    find $1 -name "*.odt" | while read file
    do
            unzip -ca "$file" content.xml | grep -qli "$2"
            if [ $? -eq 0 ]; then
                    echo "Found keyword in: " $file
            fi
    done
    You provided part of the solution for me and I ran with it from there.

    Thanks!

    Mel
    Last edited by MelIrizarry; September 26th, 2008 at 04:15 PM.

  5. #15
    Join Date
    Jul 2007
    Beans
    185

    Re: [SOLVED] Search multiple .odt files

    Post removed
    Last edited by triplemaya; March 27th, 2009 at 08:42 AM. Reason: Retrospective recognition of idiocy

  6. #16
    Join Date
    Feb 2006
    Location
    North Dakota
    Beans
    224
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Search multiple .odt files

    Quote Originally Posted by ad_267 View Post
    Code:
    for file in $(ls *.odt); do
    unzip -p "$file" content.xml | grep -l "search term" > /dev/null
    if [ $? -eq 0 ]; then
    echo "$file"
    fi
    done
    I like this and made it into a function. Paste this into your ~/.bashrc. Then you can use "odtgrep search\ term" to search all *.odt files for your term. tidy cleans up the XML so grep can return the line result without too much mess.

    Code:
    function odtgrep(){
        term="$1"
        for file in *.odt; do
            unzip -p "$file" content.xml | tidy -q -xml 2> /dev/null | grep "$term";
            if [ $? -eq 0 ]; then
                echo $file;
            fi;
        done 
    }
    Search first, ask questions later!
    From Thread Tools, "Mark this thread as solved" if your problem's been solved.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •