有人知道如何使用shell来比较两个文件吗?并找到它们之间的不同内容,例如1.txt包含1023名称,2.txt包含800,我想知道1.txt和2之间的223名称不同.txt
comm
不过,您必须对其进行文件排序。
sort 1.txt > 1.sorted.txt
sort 2.txt > 2.sorted.txt
comm -3 1.sorted.txt 2.sorted.txt
请注意,这还会告诉您 2 中是否有 1 中不存在的行。它持有较少的线并不一定意味着它们都存在于 1 中。
# only show lines that are in 1 or 2, but not both
comm -3 1.sorted.txt 2.sorted.txt
# only show lines that are unique to 1
comm -23 1.sorted.txt 2.sorted.txt
# only show lines that are unique to 2
comm -13 1.sorted.txt 2.sorted.txt