31 lines
697 B
Bash
31 lines
697 B
Bash
|
|
#!/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
|
||
|
|
|