如何匹配两个csv文件列以获得新文件

如何匹配两个csv文件列以获得新文件

我有两个 csv 文件:

第一个文件:

"ACCOUNT_CODE","FK_CLIENT_CODE","ENVIRONMENT","HHID"  
"13445319","V8571485","SAT","IT00000000000005676070"  
"10580347","V6559553","SAT","IT00000000000003952833"   
"22124274","V11943127","DTT","IT00000000000008535651"   
"11896497","V7524852","SAT","IT00000000000005652668"  

第二个文件:

IT00000000000005676070   
IT00000000000000060265           
IT00000000000008535651   
IT00000000000000060267         

这两个文件都有数百万行。我想要将第一个文件的值(称为 HHID 的最后一列的值)与第二个文件的值进行匹配。这些值未排序,我希望对于每个 HHID,在整个第二个文件中执行搜索。

如果未找到该值,将使用第二个文件中不存在的值创建第三个文件。新文件示例:

第三个文件:

"ACCOUNT_CODE","FK_CLIENT_CODE","ENVIRONMENT","HHID" 
"10580347","V6559553","SAT","IT00000000000003952833"       
"11896497","V7524852","SAT","IT00000000000005652668"

请你帮助我好吗?

答案1

$ awk 'NR==FNR{a[$1];next} !($8 in a)' file2 FS='"' file1
"ACCOUNT_CODE","FK_CLIENT_CODE","ENVIRONMENT","HHID"
"10580347","V6559553","SAT","IT00000000000003952833"
"11896497","V7524852","SAT","IT00000000000005652668"

相关内容