Closed dennisangemi closed 1 year ago
Here's a simple way to transpose a CSV with Miller:
mlr --csv -N put -q '
for (k,v in $*) { @arr[k][NR] = v }
end { emit @arr }
' file.csv
ref: https://github.com/johnkerl/miller/issues/321#issuecomment-1340147653
Questo funziona per un singolo file
#!/bin/bash
set -e
#if frct-schema-3.csv exists, delete it
if [ -f frct-schema-3.csv ]; then
rm frct-schema-3.csv
fi
# if frct-example-3.csv exists, delete it
if [ -f frct-example-3.csv ]; then
rm frct-example-3.csv
fi
cat datapackage.yaml | yq '[.resources[3].schema.fields[] | {Field: .name, Type: .type, Description: .description}]' | mlr --j2c cat > frct-schema-3.csv
echo "Field,Example" >> frct-example-3.csv
mlr --csv head -n 1 data/trasmissioni.csv | mlr --csv -N put -q 'for (k,v in $*) { @arr[k][NR] = v } end { emit @arr }' >> frct-example-3.csv
# join frct-schema-3.csv and frct-example-3.csv joinkeys=Field
mlr --csv join -j Field -f frct-schema-3.csv frct-example-3.csv > frct-schema-3.csv
# if frct-example-3.csv exists, delete it
if [ -f frct-example-3.csv ]; then
rm frct-example-3.csv
fi
if file path of datapackage is valid add example column in data data dictionary tables
Ref https://github.com/johnkerl/miller/issues/321