Last active
November 11, 2018 09:55
-
-
Save gwpl/4bc476457156f88cdf64121cbe57fad0 to your computer and use it in GitHub Desktop.
grepping odt files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
# odtgrep.sh IamSearchingThis *.odt | |
# find -name '*.odt' -exec odtgrep.sh IamSearchingThis "{}" \; | |
# or | |
# odtgrep.sh -C 5 IamSearchingThis *.odt | |
# find -name '*.odt' -exec odtgrep.sh -C 5 IamSearchingThis "{}" \; | |
# odtgrep original inspiration: | |
# https://ubuntuforums.org/showthread.php?t=899179&page=2&s=7fcc7620d05f9e432067ab40d71e40d4 | |
# related tweet | |
# tweet: https://twitter.com/GWierzowiecki/status/1061547654889566208 | |
# coloring from : https://stackoverflow.com/a/20910449/544721 | |
norm="$(printf '\033[0m')" #returns to "normal" | |
bold="$(printf '\033[0;1m')" #set bold | |
red="$(printf '\033[0;31m')" #set red | |
boldred="$(printf '\033[0;1;31m')" #set bold, and set red. | |
function odtgrep(){ | |
grep='grep --color=always' | |
if [ "$1" == '-C' ]; then | |
grep="${grep} -C $2" | |
shift 2 | |
fi | |
term="$1" | |
shift 1 | |
for file in "$@"; do | |
unzip -p "$file" content.xml | tidy -q -xml 2> /dev/null | $grep "$term"; | |
if [ $? -eq 0 ]; then | |
echo "${bold}${file}${norm}"; | |
fi; | |
done | |
} | |
odtgrep "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment