这是我的代码红宝石脚本:看跌删除重复循环
pattern = /066-\d\d\d\-\d\d\d\-\d\d\d\-\d\d\/
Dir['c:/WurtsmithClean/DRCs/*.txt'].each do |file|
next unless File.file?(file)
File.open(file) do |f|
f.each_line do |line|
if line.match(pattern)
ln = line.match(pattern)
file.gsub!('c:/WurtsmithClean/DRCs/', '')
file.gsub!('txt', 'pdf')
puts file + "," + ln.to_s
end
end
end
end
所以这个脚本看重的是“066 - ### - ### - ### - ##”匹配模式中所有文本文件在每行的c:/ WurtsmithClean/DRCs /目录中,并输出文件名和匹配,两者之间用逗号分隔以便导入CSV。
但我一直在试图弄清楚如何删除重复的匹配,因为它发现多个匹配具有相同的文件名相同的数字。我希望这些删除。我尝试过使用UNIQ()方法,但它似乎只适用于数组。虽然整个输出在技术上是循环完成后的数组,但我不知道如何将最终输出作为数组引用并删除重复项。
这里的输出是现在怎么样:
066-018-400-001-00 DRC#26.pdf,066-018-400-001-00
066-018-400-001-00 DRC#26.pdf,066-018-400-001-00
066-019-100-001-00 DRC#19.pdf,066-019-100-001-00
066-019-100-001-00 DRC#19.pdf,066-019-100-001-00
066-019-100-001-00 DRC#19.pdf,066-019-100-001-00
066-019-100-001-00 DRC.pdf,066-019-100-001-00
066-020-100-001-00 DRC#20.pdf,066-020-100-001-00
066-020-100-001-00 DRC#20.pdf,066-020-100-001-00
066-020-100-001-00 DRC#20.pdf,066-020-100-001-00
066-020-100-001-00 DRC#20.pdf,066-020-100-001-00
我希望它这样的输出(无重复):
066-018-400-001-00 DRC#26.pdf,066-018-400-001-00
066-019-100-001-00 DRC#19.pdf,066-019-100-001-00
066-019-100-001-00 DRC.pdf,066-019-100-001-00
066-020-100-001-00 DRC#20.pdf,066-020-100-001-00
CarySwoveland no that does not wor k我需要使用匹配作为发现将输出匹配和其余的线后..我只是想要数字 – emvee 2014-09-18 20:02:31