如何将两列csv文件与awk进行比较?

如何将两列csv文件与awk进行比较?,awk,Awk,我有两个csv文件需要与一列进行比较 我的member.csv文件如下所示: ID|lastName|firstName 01|Lastname01|Firstname01 02|Lastname02|Firstname02 Lastname01|Name01|pubID01|Hash01 Lastname02|Name02|pubID02|Hash02a Lastname03|Name03|pubID03|Hash03 Lastname02|Name02|pubID02|Hash02b La

我有两个csv文件需要与一列进行比较

我的
member.csv
文件如下所示:

ID|lastName|firstName
01|Lastname01|Firstname01
02|Lastname02|Firstname02
Lastname01|Name01|pubID01|Hash01
Lastname02|Name02|pubID02|Hash02a
Lastname03|Name03|pubID03|Hash03
Lastname02|Name02|pubID02|Hash02b
Lastname01|Name01|pubID01|Hash01b
第二个文件
check-ID.csv
如下所示:

ID|lastName|firstName
01|Lastname01|Firstname01
02|Lastname02|Firstname02
Lastname01|Name01|pubID01|Hash01
Lastname02|Name02|pubID02|Hash02a
Lastname03|Name03|pubID03|Hash03
Lastname02|Name02|pubID02|Hash02b
Lastname01|Name01|pubID01|Hash01b
-->
Lastname03
不在my
member.csv中

我想检查
check-ID.csv
的第一列的值是否等于
member.csv
中第二列的值

我对
script.awk
的尝试失败

NR==FNR{a[$1]=$1; b[$1]=$0; next} 
$2==a[$1]{ delete b[$1]}

END{for (i in b ) print b[i]}
执行

awk-f script.awk check-ID.csv member.csv

问题是结果没有被过滤

我希望得到一个经过筛选和排序的输出,这样只有成员才会像下面这样列出:

Lastname01|Name01|pubID01|Hash01
Lastname01|Name01|pubID01|Hash01b
Lastname02|Name02|pubID02|Hash02a
Lastname02|Name02|pubID02|Hash02b

感谢您的帮助

你能试试下面的吗。我认为你们很接近,唯一的事情是你们可以改变你们的输入文件读取顺序。我首先阅读
成员
输入文件,然后是
check-ID.csv
,因为稍后的输入文件中包含所有需要打印的详细信息,我们只需要检查成员输入文件中的第二个字段

awk '
BEGIN{
  FS="|"
}
FNR==NR{
  a[$2]
  next
}
($1 in a)
' members.csv check-ID.csv | 
sort -t'|' -k1
说明:添加上述内容的详细说明

awk '                             ##Starting awk program from here.
BEGIN{                            ##Starting BEGIN section of this program from here.
  FS="|"                          ##Setting field separator as | here.
}
FNR==NR{                          ##Checking condition if FNR==NR which will be TRUE when first Input_file named members.csv is being read.
  a[$2]                           ##Creating array a with index 2nd field here.
  next                            ##next will skip all further statements from here.
}
($1 in a)                         ##Checking condition if 1st field is preent in a then print that line.
' members.csv check-ID.csv |      ##Mentioning Input_file names here and sending its output to sort command.
sort -t'|' -k1                    ##Sorting output(which we got from awk command above) by setting separator as | and by first field.

你能试试下面的吗。我认为你们很接近,唯一的事情是你们可以改变你们的输入文件读取顺序。我首先阅读
成员
输入文件,然后是
check-ID.csv
,因为稍后的输入文件中包含所有需要打印的详细信息,我们只需要检查成员输入文件中的第二个字段

awk '
BEGIN{
  FS="|"
}
FNR==NR{
  a[$2]
  next
}
($1 in a)
' members.csv check-ID.csv | 
sort -t'|' -k1
说明:添加上述内容的详细说明

awk '                             ##Starting awk program from here.
BEGIN{                            ##Starting BEGIN section of this program from here.
  FS="|"                          ##Setting field separator as | here.
}
FNR==NR{                          ##Checking condition if FNR==NR which will be TRUE when first Input_file named members.csv is being read.
  a[$2]                           ##Creating array a with index 2nd field here.
  next                            ##next will skip all further statements from here.
}
($1 in a)                         ##Checking condition if 1st field is preent in a then print that line.
' members.csv check-ID.csv |      ##Mentioning Input_file names here and sending its output to sort command.
sort -t'|' -k1                    ##Sorting output(which we got from awk command above) by setting separator as | and by first field.