shell – 为什么使用忽略匹配行的diff不能按预期工作?
发布时间:2020-12-15 18:59:11 所属栏目:安全 来源:网络整理
导读:我有以下文件: FILE1.TXT ###################################################Dump stat Title information for 'ssummary' view###################################################Tab= 'Instance' Title= {text {Total instances: 7831}}Tab= 'Device
我有以下文件:
FILE1.TXT ################################################### Dump stat Title information for 'ssummary' view ################################################### Tab=> 'Instance' Title=> {text {Total instances: 7831}} Tab=> 'Device' Title=> {text {Total spice devices: 256}} Tab=> 'Memory' Title=> {text {Total memory allocated: 962192 kB}} Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 9030 ms}} FILE2.TXT ################################################### Dump stat Title information for 'ssummary' view ################################################### Tab=> 'Instance' Title=> {text {Total instances: 7831}} Tab=> 'Device' Title=> {text {Total spice devices: 256}} Tab=> 'Memory' Title=> {text {Total memory allocated: 9621932 kB}} Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 90303 ms}} 我正在运行以下命令: diff -I 'Memory' file1.txt file2.txt 哪个输出: 6,7c6,7 < Tab=> 'Memory' Title=> {text {Total memory allocated: 962192 kB}} < Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 9030 ms}} --- > Tab=> 'Memory' Title=> {text {Total memory allocated: 9621932 kB}} > Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 90303 ms}} 但是我的预期输出是: < Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 9030 ms}} --- > Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 90303 ms}} 请注意,在命令中如果我将“Memory”更改为“Tab”或“Title”问题已解决,但可能所有行都被忽略,因为它们都有Tab和Title.
这种行为确实看起来有点奇怪.我通过调整输入文件注意到了一些事情(我只是将“Memory”行移到了两个文件的顶部):
FILE1.TXT ################################################### Dump stat Title information for 'ssummary' view ################################################### Tab=> 'Memory' Title=> {text {Total memory allocated: 962192 kB}} Tab=> 'Instance' Title=> {text {Total instances: 7831}} Tab=> 'Device' Title=> {text {Total spice devices: 256}} Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 9030 ms}} FILE2.TXT ################################################### Dump stat Title information for 'ssummary' view ################################################### Tab=> 'Memory' Title=> {text {Total memory allocated: 9621932 kB}} Tab=> 'Instance' Title=> {text {Total instances: 7831}} Tab=> 'Device' Title=> {text {Total spice devices: 256}} Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 90303 ms}} 普通的差异会给你: diff file1.txt file2.txt 4c4 < Tab=> 'Memory' Title=> {text {Total memory allocated: 962192 kB}} --- > Tab=> 'Memory' Title=> {text {Total memory allocated: 9621932 kB}} 7c7 < Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 9030 ms}} --- > Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 90303 ms}} 请注意,现在有两组差异……使用这种安排,diff -I’Memory’file1.txt file2.txt命令将起作用并输出: 7c7 < Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 9030 ms}} --- > Tab=> 'Cpu' Title=> {text {Total cumulative CPU time: 90303 ms}} 意思是,-I标志似乎仅在一组差异中的每一行与表达式匹配时才起作用.我不知道这是一个错误或预期的行为……但它肯定是不一致的. 编辑:实际上,根据GNU diff documentation,它是预期的行为.手册页不太清楚. OpenBSD diff也有-I标志,但their man page更好地解释了它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- scala – 模糊的隐含值是我们想要在编译时存在错误的唯一方
- vim编辑器常用技巧
- Jmeter插件开发
- webservices原理
- angularjs – 使用Angular CLI的Web应用程序不显示bootstra
- 升级angularJS时获取“TypeError:ngModelCtrl.$render不是
- angularjs – Angular UI Bootstrap – 第一次点击时不会弹
- twitter-bootstrap – 如何从bootswatch .less文件开始重新
- bash – 针对shell脚本的漂亮打印
- webservice快速入门-使用JAX-WS注解的方式快速搭建ws服务端