linux diff与comm命令比较文件(找出新增内容)(2)
代码如下: $ cat temp1.txt 20110224 20110225 20110228 20110301 20110302 $ cat temp2.txt 20110228 20110301 20110302 20110303 20110304 $ diff temp1.txt temp2.txt temp.diff $ cat temp.diff 1,2d0 20110
代码如下:
$> cat temp1.txt
20110224
20110225
20110228
20110301
20110302
$> cat temp2.txt
20110228
20110301
20110302
20110303
20110304
$> diff temp1.txt temp2.txt > temp.diff
$> cat temp.diff
1,2d0
< 20110224
< 20110225
5a4,5
> 20110303
> 20110304
# 使用temp.diff和temp1.txt恢复temp2文件
$> patch -i temp.diff -o temp2_restore.txt temp1.txt
Looks like a normal diff.
done
# 完成后temp2_restore和原temp2文件内容一致
$> cat temp2_restore.txt
20110228
20110301
20110302
20110303
20110304
精彩图集
精彩文章