Skip to content

Instantly share code, notes, and snippets.

@pablopers
Created July 2, 2018 09:38
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 pablopers/143ac258826f4873d0c4fa50d6061726 to your computer and use it in GitHub Desktop.
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.
#!/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