代码之家  ›  专栏  ›  技术社区  ›  hekevintran

在Python中生成文本修订历史的视图

  •  2
  • hekevintran  · 技术社区  · 16 年前

    版本1:

    1955年10月28日)[2]是美国人 商业巨头、慈善家和 微软董事长[3],软件 他和保罗·艾伦创立的公司。

    版本2:

    威廉·亨利“比尔”盖茨三世(生于 微软董事长[3],软件 他和保罗·艾伦创立的公司。 他是美国人。

    威廉·亨利“比尔”盖茨三世(生于 北美 商业 大亨、慈善家和 微软董事长[3],软件 他和保罗·艾伦创立的公司。

    使用diff命令不起作用,因为它告诉我哪些行是不同的,而不是哪些列/字是不同的。

    $ echo 'William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.' > oldfile
    $ echo 'William Henry "Bill" Gates III (born October 28, 1955)[2] is a business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.  He is American.' > newfile
    $ diff -u oldfile newfile
    --- oldfile 2010-04-30 13:32:43.000000000 -0700
    +++ newfile 2010-04-30 13:33:09.000000000 -0700
    @@ -1 +1 @@
    -William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.
    +William Henry "Bill" Gates III (born October 28, 1955)[2] is a business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.  He is American.' > oldfile
    
    3 回复  |  直到 16 年前
        1
  •  1
  •   mikerobi    16 年前
        2
  •  0
  •   Matthew Flaschen    16 年前

    你可以用 wdiff

    $ wdiff oldfile newfile
    William Henry "Bill" Gates III (born October 28, 1955)[2] is [-an American-] {+a+} business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.  {+He is American.+}
    
        3
  •  0
  •   Epcylon    16 年前

    这个 difflib 模块可能有助于解决此问题。

    推荐文章