【发布时间】:2022-01-09 20:06:36
【问题描述】:
关于如何匹配 2 个单独文件中的 2 个字段/列,包括记录的条件匹配(状态 Employee.txt 中的“X”和可用性 = Car.txt 中的“Y”),我再次需要您的帮助。 Employee.txt($1 - 员工编号,$2 - 运动)。 Car.txt($4 - 员工编号,$2 - 运动)。以下是我想要实现的目标:
Employee1.txt (last column is the **status**)
1|canoeing|Sam|Smith|Seatle|X
2|jogging|Barry|Jones|Seatle|
3|football|Garry|Brown|Houston|
4|jogging|George|Bla|LA|X
5|basketball|Celine|Wood|Atlanta|
6|tennis|Jody|Ford|Chicago|
Car1.txt (last column is **availability**)
100|football|blue|5|Y
110|tennis|green|9|N
120|hockey|yellow|8|N
130|football|yellow|6|N
140|jogging|red|2|Y
150|canoeing|white|0|
awk -F"|" '
NR==FNR {
if ($NF == "Y")
car[$4,$2]
next
}
{
print > ($NF != "X" && ($1,$2) in car ? "match.txt" : "no_match.txt")
}' Car.txt Employee.txt
no_match.txt is the same as Employee.txt. Zero records in match.txt.
Desire output:
match.txt
2|jogging|Barry|Jones|Seatle|
5|basketball|Celine|Wood|Atlanta|
no_match.txt
3|football|Garry|Brown|Houston|
6|tennis|Jody|Ford|Chicago|
非常感谢, 乔治
【问题讨论】:
-
请将该单片灰色文本块分隔为输入、输出和代码文件的单独块,并在中间插入说明性文本。
-
您应该为此类任务安装一些关系数据库。 (例如 Access、Sqlite、MySql)。
-
我已经有了,但只是想在进行大规模记录更新之前收集数据。谢谢