代码之家  ›  专栏  ›  技术社区  ›  Chris R

为什么diff显示这两个文件有区别?

  •  0
  • Chris R  · 技术社区  · 14 年前

    出于某种原因,diff没有像预期的那样响应-w选项;两个文件都是相同的,只是在XML头的末尾有一个新行。

    我用-w选项调用diff,如下所示:

    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"/>
    

    如果把旗交给diff,为什么会有不同的结果呢?

    2 回复  |  直到 14 年前
        1
  •  2
  •   The Archetypal Paul    14 年前

    Diff逐行比较。所以换行符不是换行符

    -西

    比较时忽略空白 线。

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

        2
  •  0
  •   Mirek Kratochvil    14 年前

    来自diff手册:

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

    似乎换行符不是空白。

    如果这不起作用,检查xxd文件,其中一个可能有UTF8头或类似的不可见二进制问题。

    推荐文章