This question is an exact duplicate of:
- jq - bash script for csv to json with arrays? 2 answers
I have a csv file, i need to read the rows one by one without removing any char like , " ; etc
in.csv
{ "customer": { "name": "abc", "email":"mailme2@xxx.com","account_classification": "xyz"} }
{ "customer": { "name": "def", "email":"mailme2@xxx.com","account_classification": "xyz"} }
{ "customer": { "name": "g,h", "email":"mailme2@xxx.com","account_classification": "xyz"} }
My code
declare -a demo=($(cat in.csv))
for i in "${demo[@]}"
do
echo "$i"
done
Output (expected output)
{ "customer": { "name": "abc", "email":"mailme2@xxx.com","account_classification": "xyz"} }
{ "customer": { "name": "def", "email":"mailme2@xxx.com","account_classification": "zyx"} }
Output i am getting like (output with above code):
"{ ""customer"": { ""name"": ""abc"", ""email"":""mailme2@xxx.com"",""account_classification"": ""xyz""} }" "{ ""customer"": { ""name"": ""def"", ""email"":""mailme2@xxx.com"",""account_classification"": ""xyz""} }" "{ ""customer"": { ""name"": ""g,h"", ""email"":""mailme2@xxx.com"",""account_classification"": ""xyz""} }
Can someone give me sample code?