Skip to content

Instantly share code, notes, and snippets.

@bl4ckb1rd
Created August 29, 2014 20:09
Show Gist options
  • Save bl4ckb1rd/f45881fa6a91bab720b3 to your computer and use it in GitHub Desktop.
Save bl4ckb1rd/f45881fa6a91bab720b3 to your computer and use it in GitHub Desktop.
Convert files with SYLK format into csv with libreoffice
#!/bin/bash
# Path on with find search
FINDPATH="$(pwd)/files/"
# Extension to search
FILEEXTENSION="*.xls"
# Check if libreoffice it is installed
LIBREOFFICE=$(which libreoffice)
if [[ $LIBREOFFICE == *not* ]]
then
echo "Dont found libreoffice installed, exit";
exit
fi
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in $(find $FINDPATH -type f -iname $FILEEXTENSION)
do
DIRNAME=$(dirname "$f")
BASENAME=$(basename "$f")
cd "$DIRNAME"
$LIBREOFFICE --headless --convert-to csv:"Text - txt - csv (StarCalc)" "$BASENAME"
done
IFS=$SAVEIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment