背景
学习如何比较2个文件不同,便于在ORACLE分析数据块变更时用上此功能。结论
1,diff用于比较2个文件的不同2,diff用于比较2个文件的内容,显示结果如下
1c1
< mynewly
---
> my
上述具体含义请见下述测试
3,
变化标记有3种情况,各为
c --即变化,即记录发生了变化
a --即增加了记录
d --即删除了记录
测试
1,创建2个相同文件
[root@seconary test_diff]# more file1.txt
a
b
c
[root@seconary test_diff]#
[root@seconary test_diff]# more file2.txt
a
b
c
[root@seconary test_diff]#
2,比较2个相同的文件
如果2个文件相同,不显示任何信息
[root@seconary test_diff]# diff file1.txt file2.txt
[root@seconary test_diff]#
3,比较2个文件,且右文件发生变化
修改file2.txt
[root@seconary test_diff]# more file2.txt
anewly
b
c
[root@seconary test_diff]#
仅1个文件变化,diff结果显示
[root@seconary test_diff]# diff file1.txt file2.txt
1c1
< a ---这个表示第个文件的发生变化的哪一行的开头的字母,显示形式为 < a
---
> anewly --这个表示发生变化的文件的变化后的记录
再次修改file2.txt
[root@seconary test_diff]# more file2.txt
anewly
b
cnewly2
比较2个文件,如果发生变化文件的有多条记录,会把发生变化的多条记录也显示出来
[root@seconary test_diff]# diff file1.txt file2.txt
1c1
< a
---
> anewly
3c3
< c
---
> cnewly2
4,比较2个文件,左文件发生变化
删除file2.txt,继续测试
[root@seconary test_diff]# rm -rf file2.txt
[root@seconary test_diff]#
[root@seconary test_diff]# cp file1.txt file2.txt
[root@seconary test_diff]#
修改file1.txt
[root@seconary test_diff]# more file1.txt
a
bnewly
c
比较2个文件
[root@seconary test_diff]# diff file1.txt file2.txt
2c2
< bnewly --发生变化的文件,修改后的内容
---
> b --发生变化的文件,发生变化前的记行录
再次修改file1.txt
[root@seconary test_diff]# more file1.txt
asb
bnewly
c
比较2个文件
[root@seconary test_diff]# diff file1.txt file2.txt
1,2c1,2
< asb
< bnewly
---
> a
> b
删除2个比较文件,继续测试,采用单条记录多字符方式(上面测试皆采用单记录单字符)
[root@seconary test_diff]# rm file*
rm: remove regular file `file1.txt'? y
rm: remove regular file `file2.txt'? y
[root@seconary test_diff]#
[root@seconary test_diff]# more file1.txt
my
birthday
is
[root@seconary test_diff]# more file2.txt
my
birthday
is
[root@seconary test_diff]#
修改左文件file1.txt
[root@seconary test_diff]# more file1.txt
mynewly
birthday
is
比较2个文件,
[root@seconary test_diff]# diff file1.txt file2.txt
1c1 --分为3个部分,1表示左文件第1行记录,c表示是改变,1表示左文件的第1条记录变成左文件第1条记录
< mynewly --分为2个部分,变化后的行内容
--- --表示左文件和右文件
> my --分为2个部分,变化前的行内容
修改左文件
[root@seconary test_diff]# more file1.txt
mynewly
birthday
isthird
比较2个文件
[root@seconary test_diff]# diff file1.txt file2.txt
1c1
< mynewly
---
> my
3c3
< isthird
---
> is
测试下左文件新增记录,即删除deletion
[root@seconary test_diff]# more file1.txt
col1
col2
col3
[root@seconary test_diff]#
[root@seconary test_diff]# more file2.txt
col1
col2
col3
[root@seconary test_diff]#
[root@seconary test_diff]# more file1.txt
col1
col2
col3
newaddrecord
[root@seconary test_diff]#
[root@seconary test_diff]# diff file1.txt file2.txt
4d3
< newaddrecord
[root@seconary test_diff]#
测试下左文件删除记录,可见变化标识为a,即增加addition
[root@seconary test_diff]# more file1.txt
col1
col3
[root@seconary test_diff]#
[root@seconary test_diff]# diff file1.txt file2.txt
1a2
> col2
[root@seconary test_diff]#
参考资料
http://blog.chinaunix.net/uid-26000296-id-3507646.html个人简介:
8年oracle从业经验,具备丰富的oracle技能,目前在国内北京某专业oracle服务公司从事高级技术顾问。
服务过的客户:
中国电信
中国移动
中国联通
中国电通
国家电网
四川达州商业银行
湖南老百姓大药房
山西省公安厅
中国邮政
北京302医院
河北廊坊新奥集团公司
项目经验:
中国电信3G项目AAA系统数据库部署及优化
中国联通CRM数据库性能优化
中国移动10086电商平台数据库部署及优化
湖南老百姓大药房ERR数据库sql优化项目
四川达州商业银行TCBS核心业务系统数据库模型设计和RAC部署及优化
四川达州商业银行TCBS核心业务系统后端批处理存储过程功能模块编写及优化
北京高铁信号监控系统RAC数据库部署及优化
河南宇通客车数据库性能优化
中国电信电商平台核心采购模块表模型设计及优化
中国邮政储蓄系统数据库性能优化及sql优化
北京302医院数据库迁移实施
河北廊坊新奥data guard部署及优化
山西公安厅身份证审计数据库系统故障评估
联系方式:
手机:18201115468
qq : 305076427
qq微博: wisdomone1
新浪微博:wisdomone9
qq群:275813900
itpub博客名称:wisdomone1
http://blog.itpub.net/9240380/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-1816201/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9240380/viewspace-1816201/