打印一个文件中不包含在另一个文件中的行 [英] Print lines from one file that are not contained in another file

查看:35
本文介绍了打印一个文件中不包含在另一个文件中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

这篇关于打印一个文件中不包含在另一个文件中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆