加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 获取不在file2中的file1行

发布时间:2020-12-14 03:01:30 所属栏目:Linux 来源:网络整理
导读:我有两个很长但已排序的文件.如何获取不在第二个文件中的第一个文件的所有行? 文件1 0000_aaa_b0001_bccc_b0002_bcc ------ file2 have not that line0003_aaa_d0006_xxx... 文件2 0000_aaa_b0001_bccc_b0003_aaa_d0006_xxx... 解决方法 这是comm命令的用途
我有两个很长但已排序的文件.如何获取不在第二个文件中的第一个文件的所有行?

文件1

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

文件2

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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读