I have one csv file that is looking like this
NameColumn1;NameColumn2;NameColumn3;NameColumn4
Row1;Row1;Row1;Row1;
Row2;Row2;Row2;Row2;
Row3;Row3;Row3;Row3;
I want to take the values in Row1, Row2 and Row3 from NameColumn1 and put them into array,the same for NameColumn2,NameColumn3 and NameColumn4.
I don't know how much rows I will have but I know the number of columns. Any help?
Thank you.
With the -a option/flag from the builtin read.
#!/usr/bin/env bash
while IFS=';' read -ra array; do
ar1+=("${array[0]}")
ar2+=("${array[1]}")
ar3+=("${array[2]}")
ar4+=("${array[3]}")
done < file.csv
printf '%s\n' "${ar1[@]}" "${ar2[@]}" "${ar3[@]}" "${ar4[@]}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With