I am parsing a very large csv file and creating many sub-files with its contents according to the value of the first column. So far, what I have done is manually declare an array:
declare -a arr=(
"Value 1"
"Value 2"
)
and then I loop through this array and create the mini-csv files with the information I care about, also changing the name of the output csv files to swap spaces with underscores:
for i in "${arr[@]}"
do
NAME=${i// /_}
echo $header > "$outputpath/$NAME.csv"
grep "^$i," "$fixed_file" | cut -d ',' -f 4,6 >> "$outputpath/$NAME.csv"
done
Is there a way to automate the first step as well? i.e., Can I loop through the original csv file and populate arr with all unique values of its column 1?