比较文本文件的两个版本,并查找使用Ruby进行的添加/删除? [英] Compare two versions of a text file and find additions/removals with Ruby?
问题描述
我正在使用Ruby跟踪网页中的更改.删除所有html标记和空白行后,我得到了一个行数组,假设可能存在重复,需要对其进行添加/删除检查.如果已经做过,您能推荐一颗好宝石吗?
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?
推荐答案
听起来像教科书中要使用Diff算法的情况.
Sounds like a textbook case of where you'd want to use the Diff algorithm.
有一个'diff'宝石,尽管公平地说,我从未使用过它: http://rubygems. org/gems/diff
There's a 'diff' gem, although to be fair I've never used it: http://rubygems.org/gems/diff
这篇关于比较文本文件的两个版本,并查找使用Ruby进行的添加/删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!