【发布时间】:2021-12-31 07:03:13
【问题描述】:
我需要您的帮助才能从 AIX 6.x 上的以下示例中找到 Employee.txt 中不匹配的列表。
员工.txt
1|Sam|Smith|Seatle
2|Barry|Jones|Seatle
3|Garry|Brown|Houston
4|George|Bla|LA
5|Celine|Wood|Atlanta
6|Jody|Ford|Chicago
汽车.txt
100|red|1
110|green|9
120|yellow|2
130|yellow|6
140|red|8
150|white|0
bash-4.3$ awk -F"|" 'NR==FNR { empcar[$1]=$0; next } { if (empcar[$3]) print empcar[$3] "|" $1 "|" $2 > "match.txt"; else print $0 > "no_match.txt" }' Employee.txt Car.txt
110|green|9
140|red|8
150|white|0
match.txt
1|Sam|Smith|Seatle|100|red
2|Barry|Jones|Seatle|120|yellow
6|Jody|Ford|Chicago|130|yellow
no_match.txt
110|green|9
140|red|8
150|white|0
bash-4.3$ awk -F"|" 'NR==FNR { empcar[$1]=$0; next } !($3 in empcar)' employee.txt car.txt produced the same list as in the no_match.txt.
但是,我希望 no_match.txt 如下:
3|Garry|Brown|Houston
4|George|Bla|LA
5|Celine|Wood|Atlanta
也就是说,打印Employee.txt中没有员工编号的行。在 Car.txt 中。我不知道如何在 else 语句中引用那些不匹配的记录。
我在 match.txt 中也遇到了很多无法解释的重复文件,其中包含无法披露的私人机密数据。
非常感谢, 乔治
【问题讨论】: