我想知道如何将两个文件合并到一个列中并删除重复项。先举几个例子。
文件1:
SERVER1; Deployed; Infrastructure
SERVER2; Deployed; Infrastructure
SERVER3; Deployed; Infrastructure
SERVER4; Deployed; Infrastructure
SERVER5; Deployed; Infrastructure
文件2:
SERVER1;
SERVER2;
SERVER5;
期望值:
SERVER3; Deployed; Infrastructure
SERVER4; 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
然后试图从上面得到的命令中删除重复项,但似乎只删除了一行重复项,剩下一行是:
SERVER1;
SERVER2;
SERVER3; Deployed; Infrastructure
SERVER4; Deployed; Infrastructure
SERVER5;
我想检查副本并删除副本和服务器本身,您有什么建议吗?
最佳答案
以下awk
可能对您有帮助。
awk 'FNR==NR{a[$0];next} !($1 in a)' File2 File1