I have the following CSV File called test.csv
First Line, 100
Second Line, 200
Third Line, 300
Fourth Line, 400
I want to split each line at the comma and store the first part into an array in a bash script using awk. I have done the following:
#!/bin/bash
declare -a MY_ARRAY
MY_ARRAY=$(awk -F ',' '{print $1}' test.csv)
echo 'Start'
for ENTRY in ${MY_ARRAY}
do
echo ${ENTRY}
done
echo 'Stop'
And the output is as follows:
Start
First
Line
Second
Line
Third
Line
Fourth
Line
Stop
How can I get the array to hold the following?:
First Line
Second Line
Third Line
Fourth Line