Guest User

Untitled

a guest
Aug 18th, 2019
355
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. set -e
  4.  
  5. [[ $# != 2 ]] && { echo "Usage: $0 <path to XLSX file> <path to converted XLSX output>"; exit 1; }
  6.  
  7. template_path=$1
  8. output_path=$(realpath "$2")
  9.  
  10. tempdir=$(mktemp -d /tmp/rp2kilos.XXXXX)
  11. trap 'rm -f -- "$tempdir"' INT TERM HUP EXIT
  12.  
  13. echo "Unpacking template to $tempdir"
  14. unzip -q -d "$tempdir" "$template_path"
  15.  
  16. for worksheet in ${tempdir}/xl/worksheets/*.xml; do
  17.     echo "Converting ${worksheet}..."
  18.     sed -r -i 's/MROUND\(([^,]+?),5\)/MROUND(\1,2.5)/g' "$worksheet"
  19. done
  20.  
  21. echo "Zipping..."
  22. pushd "${tempdir}" >/dev/null
  23. zip  -q -r "$output_path" *
  24. popd >/dev/null
  25. echo "Converted file saved as $output_path"
  26. rm -rf "${tempdir}"
RAW Paste Data