打印一个文件中不包含在另一个文件中的行

打印一个文件中不包含在另一个文件中的行

问题描述:

我希望打印在一个文件中但不在另一个文件中的行.但是,两个文件都没有排序,我需要保留两个文件中的原始顺序.

I wish to print lines that are in one file but not in another file. However, neither files are sorted, and I need to retain the original order in both files.

 contents of file1:
 string2
 string1
 string3

 contents of file2:
 string3
 string1

 Output:
 string2

有没有我可以在其中完成此操作的简单脚本?

Is there a simple script that I can accomplish this in?

fgrep -x -f file2 -v file1

-x 匹配整行

-f FILE 从 FILE 中获取模式

-f FILE takes patterns from FILE

-v 反转结果(显示不匹配)

-v inverts results (show non-matching)