获取不在file2中的file1行 [英] Get lines of file1 which are not in file2

查看:90
本文介绍了获取不在file2中的file1行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个很长但已排序的文件.如何获取第一个文件中不在第二个文件中的所有行?

I have two long, but sorted files. How to get all lines of first file which are not in second file ?

file1

0000_aaa_b
0001_bccc_b
0002_bcc <------ file2 have not that line
0003_aaa_d
0006_xxx
...

file2

0000_aaa_b
0001_bccc_b
0003_aaa_d
0006_xxx
...

推荐答案

这是comm命令的作用:

$ comm -3 file1 file2
0002_bcc

来自man comm:

DESCRIPTION

   Compare sorted files FILE1 and FILE2 line by line.

   With  no  options,  produce  three-column  output.  Column one contains
   lines unique to FILE1, column two contains lines unique to  FILE2,  and
   column three contains lines common to both files.

   -1     suppress column 1 (lines unique to FILE1)

   -2     suppress column 2 (lines unique to FILE2)

   -3     suppress column 3 (lines that appear in both files)

这篇关于获取不在file2中的file1行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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