我想知道如何在一个列上加入两个文件并删除重复项。首先举一些例子。文件1:SERVER1; Deployed; InfrastructureSERVER2; Deployed; InfrastructureSERVER3; Deployed; InfrastructureSERVER4; Deployed; InfrastructureSERVER5; Deployed; Infrastructure文件2:SERVER1;SERVER2;SERVER5;期待:SERVER3; Deployed; InfrastructureSERVER4; Deployed; Infrastructure尝试过类似的命令:sort File1 File2 | uniq > File3,但是它只返回合并的输出,因为它确实将每一列视为唯一,输出类似于: SERVER1; SERVER1; Deployed; Infrastructure SERVER2; SERVER2; Deployed; Infrastructure SERVER3; Deployed; Infrastructure SERVER4; Deployed; Infrastructure SERVER5; SERVER5; Deployed; Infrastructure然后尝试使用命令从上面获得的内容中删除重复项awk -F";" '!_[$1]++' File3,但似乎只删除了一个重复行,而另一行是:SERVER1;SERVER2;SERVER3; Deployed; InfrastructureSERVER4; Deployed; InfrastructureSERVER5;我想检查重复项并删除重复项和服务器本身,您有什么建议吗?
3 回答
慕无忌1623718
TA贡献1744条经验 获得超4个赞
该join命令在这里工作:
$ join -t ';' -a 1 -v 2 File1 File2
SERVER3; Deployed; Infrastructure
SERVER4; Deployed; Infrastructure
加入要求对文件进行排序。如果未排序:
$ join -t ';' -a 1 -v 2 <(sort File1) <(sort File2)
慕田峪9158850
TA贡献1794条经验 获得超7个赞
您可以使用grep文件(-f)和(-v)反转匹配选项:
grep -vf File2 File1
输出:
SERVER3; Deployed; Infrastructure
SERVER4; Deployed; Infrastructure
- 3 回答
- 0 关注
- 281 浏览
添加回答
举报
0/150
提交
取消