File-template
NAME 1
CITY 2
AMOUNT 3
BAL 4
File - data
Anderson,,100,3000
File data always will have single record.
I the above case, if I want to extract value of AMOUNT from file data.
First I'll have to find position of AMOUNT in template and extract the specified column from the data.
Following is my code
column=AMOUNT -- given only for testing
pos=`cat template|grep $column | awk '{print $2}`
data=`awk -F',' '{print $pos}' data`
echo $data
Since I do not know the exact column position, I'm using $pos in the script. Which is a error. Can anybody give me a solution.