Files
FlexSurvey/server/createDataCsv.sh

31 lines
697 B
Bash
Raw Normal View History

2017-02-07 20:04:47 +00:00
#!/bin/bash
# Assumes all JSON files have the same structure.
# TODO: Current akw splitting doesn'properly handle double quotes in data resulting in data truncation.
OutFile="output.csv"
rm "$OutFile"
filename=$(ls *.JSON | head -n1)
grep ":" "$filename" | awk -F "\"" '{ print $2; }' | while read field
do
echo -e -n "\"${field/\\\"/\"\"}\""";" >> "$OutFile"
done
echo >> "$OutFile"
ls *.JSON | while read filename
do echo processing $filename
grep ":" "$filename" | awk -F "\"" '{ print $2; }' | while read field
do
fieldData=$(grep "\"$field\":" "$filename" | awk -F '"' '{ print $4; }')
echo -e -n "\"${fieldData/\\\"/\"\"}\""";" >> "$OutFile"
done
echo >> "$OutFile"
done