I am writing a shell script that reads a csv file and prints the read values:
#!/bin/bash
#echo"Starting execution in script"
exec < src/main/resources/test1.csv || exit 1
read header # read (and ignore) the first line
while IFS=, read name age salary ; do
echo "{"\"name"\":"\"${name}"\","\"age"\":${age},"\"salary"\":${salary}}"
done
test1.csv (Input file):
name,age,salary
Subhash,26.0,10000.0
Amit,25.0,20000.0
Rohit,28.0,3000.0
Manoranjan,20.0,50000.0
While running the script, I am getting the output in the following way:
}"name":"Subhash","age":26.0,"salary":10000.0
}"name":"Amit","age":25.0,"salary":20000.0
}"name":"Rohit","age":28.0,"salary":3000.0
}"name":"Manoranjan","age":20.0,"salary":50000.0
However, if I try to run the same echo line from the above script on the terminal, I am getting proper output with braces:
{"name": "subhash","age":23,"salary":1000}
What is wrong with the above script?