CSV data format
1st Format
name,email,mobile,email
a,a@test.com,1234567890,a@test.com
2nd Format
name,email,"mobile,number",email
a,a@test.com,1234567890,a@test.com
3rd Format
name,email,"mobile number",email
a,a@test.com,1234567890,a@test.com
In my above data format email is duplicate in header so I only want to keep first column value for email and second email data with header should be deleted from file.
I have tied this but it;s not working properly
awk -F'","' 'NR==1{for(i=1;i<=NF;i++)if(!($i in v)){ v[$i];t[i]}}{s=""; for(i=1;i<=NF;i++)if(i in t)s=s sprintf("%s,",$i);if(s){sub(/,$/,"",s);print s}} ' input.csv > output.csv
Please suggest script command for the same