【发布时间】:2021-09-24 14:20:04
【问题描述】:
我有两个要比较的文件。文件 1.txt 和文件 2.txt。 File1.txt 看起来像:-
name1 12.12.365.237
name2 12.90.543.87
name3 34.47.26.230
name4 11.10.90.234
name5 10.11.12.15
而我的 file2 看起来像:-
10.11.12.15
12.12.365.237
11.10.90.234
我正在尝试编写一个脚本来识别 file1 中哪些 IP 地址在 file2 中不存在,并将名称和 IP 输出到单独的文件中并将其转换为 CSV。所以所需的输出将是:-
name2 12.90.543.87
name3 34.47.26.230
我尝试像这样使用 grep :-
grep -Fxvf File2.txt File1.txt >> not-in-File2.txt
mv not-in-File2.txt not-in-File2.csv
但是 grep 命令似乎不起作用,因为它给出了错误的输出。它目前给了我整个 file1 的原样。
name1 12.12.365.237
name2 12.90.543.87
name3 34.47.26.230
name4 11.10.90.234
name5 10.11.12.15
比较这两个文件的最佳方法是什么?
【问题讨论】:
-
@markp-fuso 完成。