Created
July 2, 2018 09:38
-
-
Save pablopers/143ac258826f4873d0c4fa50d6061726 to your computer and use it in GitHub Desktop.
Uno script bash di esempio, che scarica un file (xls, xlsx o ods) da un server e lo trasforma in CSV e JSON.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### requisiti ### | |
# csvkit | |
# jq | |
### requisiti ### | |
set -x | |
# scegliere e impostare la cartella di output | |
cartella="/destinazione-dei-file" | |
# scarico il file di interesse dal server | |
curl http://192.168.x.x/assenze2018.xlsx -o "$cartella"/assenze2018.xlsx | |
# Conversione in csv | |
# con il comando sed -r 's/([0-9]+)(\.)([0-9]{2})([0-9]+)/\1\2\3/g' | |
# vengono divise le cifre ed escluse tutte quelle dopo le due cifre decimali | |
<"$cartella"/assenze2018.xlsx in2csv -I -f xlsx | sed -r 's/([0-9]+)(\.)([0-9]{2})([0-9]+)/\1\2\3/g' >"$cartella"/assenze2018.csv | |
# conversione ods to csv opzionale [decommentare la riga in caso] | |
# soffice --headless --convert-to csv *.ods | |
# Conversione in json | |
<"$cartella"/assenze2018.csv csvjson | jq . >"$cartella"/assenze2018.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment