2010-11-10 85 views
0

由于某些原因,diff对预期的-w选项没有响应;两个文件,除了XML标头末尾的单个新行外,两个文件都是相同的。为什么差异显示这两个文件存在差异?

我调用DIFF与-w选项,例如:

diff -w old_file.xml new_file.xml 

# head -n4 old_file.xml

<?xml version="1.0" encoding="utf-8"?><survey audio_access_number="" custom="" name="test_conditionFormula" title="" type="CATI"><section id="1" loopover="None" notes="" startrecording="true" title="1"> 
    <page id="1_Q1" loopover="None" notes="" title="1_Q1"><question id="Q1" number="Q1" style="vertical" text="1" uid="94"> 
     <single id="single_409" number_response_columns="1" response_list="Q1_L1"/> 
     <instructions>Please select one</instructions> 

# head -n4 new_file.xml

<?xml version="1.0" encoding="utf-8"?> 
<survey audio_access_number="" custom="" name="test_conditionFormula" title="" type="CATI"><section id="1" loopover="None" notes="" startrecording="true" title="1"> 
    <page id="1_Q1" loopover="None" notes="" title="1_Q1"><question id="Q1" number="Q1" style="vertical" text="1" uid="94"> 
     <single id="single_409" number_response_columns="1" response_list="Q1_L1"/> 

为什么这些即将到来的不同,鉴于国旗差异?

回答

2

差异逐行比较。所以,一个换行符是不是一个线

-w

比较 行时忽略空格内的空格。

http://linux.die.net/man/1/diff

+0

我也试过'-w -B','-w --ignore-all-space','-w -b -B --ignore-all-space'以及其他任何你可以混用的想像。 – 2010-11-10 20:53:31

+0

是的,你不能用差异来做。差异逐行比较,并且您有一个文件,其中的行不同。你想要运行的实际测试是什么?你可以连接所有行到一个,然后测试结果? (尽管'cmp'not'diff',因为你有差异可能有行长限制) – 2010-11-10 20:54:59

0

从DIFF手册:

-w --ignore-all-space 
       Ignore all white space. 

好像换行符不是空格。

如果这没有帮助,请使用xxd检查文件,其中一个文件可能包含UTF8标头或一些类似的不可见二进制问题。