I have a CSV file which contains the field names and values. The field names have given with a '#' Eg.
test.csv
#field_1,field_2,field_3
1,axt,3
2,bss,3
I need to display the output like this:
heading_1=field_1
heading_2=field_2
heading_3=field_3
The script I have written so far:
headings=$(grep '^#' $arg_file)
echo "Fields name= $headings"
###### put a for loop to take in all headings as separate variables
for ((i=1; i<=$(echo "$headings"|tr ',' ' '|wc -w); i++))
do
echo "Trial $i field"
heading_$i=$(echo "$headings"|cut -d "," -f $i)
var="$(heading_$i)"
echo ${!var}
done
But this is giving me an error:
./script.sh: line 28: heading_1=#field_1: command not found
./script.sh: line 29: heading_1: command not found
What should I do to get the output the way I want? I am new to shell script and I am not really sure if that is even possible.