Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eusonlito/5ffad10c25c5e5c4fd06 to your computer and use it in GitHub Desktop.
Save eusonlito/5ffad10c25c5e5c4fd06 to your computer and use it in GitHub Desktop.
Merge multiple XLS to a new CSV file from command line
#!/bin/bash
HEADER_START='ALL_HEADERS_START_WITH_THIS'
DELETE_PREVIOUS_CSV=true
FILE='merged-xls.csv'
if [ "$DELETE_PREVIOUS_CSV" == "true" ]; then
rm -f *.csv
fi
unoconv -f csv *.xls
if [ -z "$HEADER_START" ]; then
cat *.csv > "$FILE.tmp"
else
grep -m 1 -h "^$HEADER_START" *.csv | head -1 > "$FILE.tmp"
grep -hv "^$HEADER_START" *.csv >> "$FILE.tmp"
fi
if [ "$DELETE_PREVIOUS_CSV" == "true" ]; then
rm -rf *.csv
fi
mv "$FILE.tmp" "$FILE"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment