shell – 为什么使用忽略匹配行的diff不能按预期工作?

我有以下文件

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更好地解释了它.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...