Wed 29 Jun 2016 03:35:00 PM UTC, original submission:
The ODF document format is not plain-text; it is a compressed file, containing content.xml which has the text in it, in XML format.
There are some simple scripts that were developed (I'll link to and copy them below), but in one the arguments order is changed (file comes first -- so only one file can be specified); in another it only handles files in the current directory; and they're both not as easy to use as having this built in to grep.
I am putting a $50 bounty on fixing this, as well, at bountysource.com (I am "Brother Ken" there, with a space, which wasn't allowed in usernames here; I signed up there first).
The following page contains a writeup and a script:
http://www.techrepublic.com/blog/linux-and-open-source/how-to-search-for-text-inside-many-opendocument-files/
The following thread also has several scripts, developed by the users, and appears to be the source of the previous article's inspiration (the last one, on page 2):
http://ubuntuforums.org/showthread.php?t=899179&page=2
Here's the script from the first article:
function odfgrep(){
FILE=$1
shift
EXT=`echo ${FILE##*.}`
case $EXT in
odt|ods|odp)
unzip -p "$FILE" content.xml | tidy -q -xml 2> /dev/null | grep "$@" ;;
txt|t2t)
grep "$@" "$FILE" ;;
*) echo "Sorry, I don't know what to do with $FILE"
;;
esac
}
Here's the final script from the second article:
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
}
The important line in both cases is the one that starts with "unzip"; that's how to handle an ODF file.
This will require a command-line switch to activate this processing, so that grep's behavior continues to be as otherwise expected. (Then I would set GREP_OPTIONS on my system to include it.) The parameter name can be whatever is available and fits the existing naming heuristics.
|