pulling different fields from a csv file

Hi,

I have a requirment where I need to pull different columns from a .csv file.

Here is the sample of the csv file.

account,item,flag1,flag2,flag3,flag4,flag5,......feed,tran

I will be have a config.txt file which will have the following information.

item,flag5,flag10,feed,tran
account,flag1,flag4,flag15,tran
Using the config file I need to pull all the data in that columns provided into to two separte files.

Please let me know if you need more information.

Try:

i=0;while read line; do i=$((i+1));echo $line | awk -F, 'NR==1{for (i=1;i<=NF;i++){a[$i]}}NR==2{for (i=1;i<=NF;i++){if ($i in a){b}}}
NR>2{for (i=1;i<=NF;i++){if (i in b){printf $i","}}printf "\n"}' - file.csv | perl -pe 's/,$//' > file$i; done<config.txt

Thank you very much.