Skip to content

Instantly share code, notes, and snippets.

@hell0again
Created May 8, 2014 17:38
Show Gist options
  • Save hell0again/1f5c9f6f1f84fb1690ec to your computer and use it in GitHub Desktop.
Save hell0again/1f5c9f6f1f84fb1690ec to your computer and use it in GitHub Desktop.
xlsxをunzipしてxmllint formatして再度zipにする
#!/bin/bash
## xlsxをunzipしてxmllint formatして再度zipしても読める事を確認
# FLATTEN2の中身を直接書き換えて最後のzipコマンドを実行してもxlsxとして読める
ORIGINAL=time_sample.xlsx
FLATTEN1=flatten
FLATTEN2=reflatten
REZIP1=flatten.xlsx
REZIP1=reflatten.xlsx
rm -rf ${REZIP1} ${REZIP2} ${FLATTEN1} ${FLATTEN2}
unzip ${ORIGINAL} -d ${FLATTEN1}
cd ${FLATTEN1}
zip ../${REZIP1} $(find .)
unzip ../${REZIP1} -d ../${FLATTEN2}
cd ../${FLATTEN2}
for i in $( find . -name "*.xml" -o -name "*.rels"); do
(rm $i; xmllint --format - >$i) <$i
done
zip ../${REZIP2} $(find .)
cd ../
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment