I am trying to create a while loop so that it takes content from one file and creates some content on another file. But what i noticed is that it is only creating the last line of the file instead of all the lines in the file. What am i missing here? Or is my approach with echo wrong?
My file called "test" contains a list of strings for ex.
unix_idx
web_pn_iis
wis_healthpartners
I am using the following command to try and create a while loop.
while read -r line;
do
echo " {
\"name\": \"$line\",
\"datatype\": \"event\",
\"searchableDays\": 180,
\"maxDataSizeMB\": 0,
\"totalEventCount\": \"0\",
\"totalRawSizeMB\": \"0\"
}," > myfile.json;
done < test;
but once the command is run myfile.json only contains the last line read from the test file. i.e wis_healthpartners
{
"name": "wis_healthpartners",
"datatype": "event",
"searchableDays": 180,
"maxDataSizeMB": 0,
"totalEventCount": "0",
"totalRawSizeMB": "0"
},
So i think the echo is over writing the lines as the while loop runs and it is left with only the last line. How do i tweak this so that it contains all the lines together? My desired output is as below.
{
"name": "unix_idx",
"datatype": "event",
"searchableDays": 180,
"maxDataSizeMB": 0,
"totalEventCount": "0",
"totalRawSizeMB": "0"
},
{
"name": "web_pn_iis",
"datatype": "event",
"searchableDays": 180,
"maxDataSizeMB": 0,
"totalEventCount": "0",
"totalRawSizeMB": "0"
},
{
"name": "wis_healthpartners",
"datatype": "event",
"searchableDays": 180,
"maxDataSizeMB": 0,
"totalEventCount": "0",
"totalRawSizeMB": "0"
},