diff命令和写入输出到制表符分隔文件

时间:2015-02-17 19:41:07

标签: bash

我有两个txt文件

文件1:

a 1
b 2
d 4

和文件2:

a 1
d 4

我希望file1但不在file2中的行位于以file3分隔的标签中,即

b 2

我用

diff file1 file2 | grep ">" > file3

file3有正确的台词,但我想摆脱“>”符号

你能建议我怎么做吗?

2 个答案:

答案 0 :(得分:4)

您不希望diff {@ 1}} {。}}。

comm

答案 1 :(得分:2)

这是一个awk命令,不需要对输入文件进行排序:

awk 'FNR==NR{a[$0]; next} !($0 in a)' file2 file1
b 2

<强>解释

FNR==NR     # execute this block for first file in the list (file2)
a[$0]       # populate an associative array with key as $0 (full line)
next        # move to next record
!($0 in a)  # for 2nd file in list (file1) print if a record doesn't exist in array a