龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 操作系统 > LINUX系统 >

linux diff与comm命令比较文件(找出新增内容)(2)

时间:2014-05-26 02:13来源:网络整理 作者:网络 点击:
分享到:
代码如下: $ 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

精彩图集

赞助商链接