文本处理:比较两个排序的文件并根据第二列排除不同的行

Text processing: compare two sorted files and exclude different lines, based on second column

文件A

232 com.path.class1
32  com.path.class2
123 com.path.class3

文件B

675 com.path.class6
567 com.path.class2
657 com.path.class1

noLines(文件A) > noLines(文件B)

我想从文件 A 中删除第 2 列(包含 类 的行)在文件 B 中不存在的所有行

关注 awk 可能会对您有所帮助。

awk 'FNR==NR{a[];next} ( in a)' fileB fileA

如果您想将输出保存到 Input_file fileA 本身,那么也将 > temp_file && mv temp_file fileA 附加到上面的代码。

with join(期望文件排序;所以排序)

$ join -j2 -o1.1,1.2 <(sort -k2 file1) <(sort -k2 file2)

232 com.path.class1
32 com.path.class2