Last active
February 23, 2021 16:05
-
-
Save andrekutianski/b90d80f20bb757a7b012ad9752d2fb0f to your computer and use it in GitHub Desktop.
Bash script to convert all geojson files present on the basedir to a csv using json2csv. requires https://www.npmjs.com/package/json2csv
This file contains hidden or 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 | |
i=0 | |
fields="properties.inscrlig,properties.ncodimov,properties.ninscrao,properties.nmatricu,properties.ncodcont,properties.nlogrado,properties.nnumimov,properties.ncomplem,properties.nnomebai" | |
dirname=${PWD##*/} | |
output="inscricoes_$dirname.csv" | |
for f in *.geojson; do | |
filename="$f" | |
printf "Processando arquivo $filename \n" | |
if [ $i -eq 0 ]; then | |
printf "Arquivo CSV inexistente, criando $output \n" | |
json2csv -i $filename -a -f $fields | xargs printf '%s\n' 1> $output 2>> error.log | |
printf "Arquivo criado \n" | |
fi | |
if [ $i -eq 1 ]; then | |
#statements | |
json2csv -i $filename -a -f $fields --no-header | xargs printf '%s\n' 1>> $output 2>> error.log | |
printf "Arquivo $filename processado \n" | |
fi | |
i=1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment