Skip to content

Instantly share code, notes, and snippets.

@tomfaulhaber
Created March 21, 2016 23:48
Show Gist options
  • Save tomfaulhaber/4f1db38af6e57ac648e9 to your computer and use it in GitHub Desktop.
Save tomfaulhaber/4f1db38af6e57ac648e9 to your computer and use it in GitHub Desktop.
A shell script that takes an Excel file and a directory and expands the Excel file into that directory as separate files, nicely formatting all the XML files so that they are actually readable.
#!/bin/bash
# Process command line arguments
REPS=10
PREFIX=bench
SCRIPT=
function show_help() {
cat <<EOF 1>&2
Usage: unzip-excel <excel-file> <output-dir>
Unzip an excel file into a directory and prettify all the xml files
EOF
}
while [[ $# > 0 ]]
do
key="$1"
case $key in
-h|--help)
show_help
exit 0
;;
-*)
echo "Unknown argument '$key'." 1>&2
show_help
exit 1
;;
*)
break
;;
esac
shift # past argument or value
done
if [[ $# != 2 ]]
then
echo "Not enough arguments" 1>&2
show_help
exit 1
fi
INPUT=$1
OUTDIR=$2
if [ ! -f ${INPUT} ]
then
echo "Input file '${INPUT}' doesn't exist, aborting..." 1>&2
exit 1
fi
if [ -d ${OUTDIR} ]
then
echo "Output directory '${OUTDIR}' already exists. Use a new directory name." 1>&2
exit 1
fi
mkdir ${OUTDIR}
cd ${OUTDIR}
unzip ${INPUT} -d.
for file in $(find . -name "*.xml*" -print); do xmllint --format $file > /tmp/out; mv /tmp/out $file; done
touch .projectile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment