比较两个文件的行,打印第一个文件特有的行 [英] Compare lines of two files, print lines unique to first file

查看:38
本文介绍了比较两个文件的行,打印第一个文件特有的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本文件,其中包含唯一的单词排序列表:

I have two text files that contain a unique sorted list of words:

文件1:

a
b
c
d

文件2:

b
c

我需要一个仅包含文件1中多余行的新文件,因此结果将是

I need a new file that contains only the extraneous lines in File 1, so the result will be

a
d

推荐答案

这是 comm 适用于:

This is what comm is for:

通讯-选择或拒绝两个文件共有的行

comm -- select or reject lines common to two files

你想要

comm -23 "File 1" "File 2"

这将仅抑制文件2中的行和两个文件中的的输出,而文件1中仅保留行的输出.更多答案此处是Greg Wooledge Wiki上的

which will suppress output of lines only in file 2 and lines in both files, leaving only lines in file 1. More answers here on Greg Wooledge's wiki

这篇关于比较两个文件的行,打印第一个文件特有的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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