Filtering first file columns based on second file column

view story

http://www.unix.com – Hi friends, I have one file like below. (.csv type) Code: SNo,data1,data2 1,1,2 2,2,3 3,3,2 and another file like below. Code: Exclude data1 where Exclude should be treated as column name in file2. I want the output shown below. Code: SNo,data2 1,2 2,3 3,2 Where my data1 column got removed from my first file as it is mentioned in next file. In reality i have 1000's of columns in my file 1 and want to remove some of them by keep updating in second file. I got a one liner R code, but to load the first file and writing the result into another file is taking lot of time as wel (HowTos)