Skip to content

Instantly share code, notes, and snippets.

@fbarriga
Last active December 15, 2017 20:58
Show Gist options
  • Save fbarriga/47370f1d2c3fc648e9230ecfc0d1531f to your computer and use it in GitHub Desktop.
Save fbarriga/47370f1d2c3fc648e9230ecfc0d1531f to your computer and use it in GitHub Desktop.
Search inside xlsx files (excel)
#!/usr/bin/env sh
#WIP
if [ $# -ne 2 ]; then
echo "Usage: $0 \"search_string\" file.xlsx"
echo " e.g.: $0 \"foo\" *.xlsx"
exit 1
fi
ls "$2" | xargs -IXXX sh -c "xlsx2txt 'XXX' | sed s/^/XXX\:\ /g" | grep "$1"

Compile and install xlsx

cat for xlsx files:

ls *.xlsx | xargs -IXXX sh -c "xlsx2txt 'XXX' | sed s/^/XXX\:\ /g"

alias for that cat:

alias xlsx_grep="ls *.xlsx | xargs -IXXX sh -c \"xlsx2txt 'XXX' | gsed s/^/XXX\:\ /g\""

now grep:

xlsx_grep | grep "searched_string"

TODO:

  • make script to support arguments. e.g.:

      xlsx_grep "searched_string" *.xlsx
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment