Compare two versions of a text file and find additions/removals with Ruby? [duplicate]

半城伤御伤魂 提交于 2020-01-07 03:37:19

问题


I am tracking changes in a web-page using Ruby. After I removed all html tags and blank lines, I get an array of lines which needs to be checked for additions/removals assuming that there may be repetitions. Could you recommend a good gem if it has been done already?

I could make the array lines unique and then the problem is avoided. But what if I need to track the repeated lines as well with respect to their position in the text?


回答1:


Sounds like a textbook case of where you'd want to use the Diff algorithm.

There's a 'diff' gem, although to be fair I've never used it: http://rubygems.org/gems/diff



来源:https://stackoverflow.com/questions/4441458/compare-two-versions-of-a-text-file-and-find-additions-removals-with-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!