我有两个txt文件
文件1:
a 1
b 2
d 4
和文件2:
a 1
d 4
我希望file1
但不在file2
中的行位于以file3
分隔的标签中,即
b 2
我用
diff file1 file2 | grep ">" > file3
file3
有正确的台词,但我想摆脱“>”符号
你能建议我怎么做吗?
答案 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