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

shell – 逐行比较两个文件,并在另一个文件中生成差异

发布时间:2020-12-15 16:40:10 所属栏目:安全 来源:网络整理
导读:我想将file1与file2进行比较,并生成一个file3,其中包含file1中不存在于file2中的行。 diff(1)不是答案,comm(1)是。 NAME comm - compare two sorted files line by lineSYNOPSIS comm [OPTION]... FILE1 FILE2... -1 suppress lines unique to FILE1 -2 s
我想将file1与file2进行比较,并生成一个file3,其中包含file1中不存在于file2中的行。
diff(1)不是答案,comm(1)是。
NAME
       comm - compare two sorted files line by line

SYNOPSIS
       comm [OPTION]... FILE1 FILE2

...

       -1     suppress lines unique to FILE1

       -2     suppress lines unique to FILE2

       -3     suppress lines that appear in both files

所以

comm -2 -3 file1 file2 > fil3

输入文件必须排序。如果不是,请先排序。这可以使用临时文件或…

comm -2 -3 <(sort file1) <(sort file2) > file3

前提是你的shell支持进程替换(bash does)。

(编辑:李大同)

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

    推荐文章
      热点阅读