#!/usr/bin/env ruby count=6 word="com" out=Array.new b='' File.open("WORD.LST","r"){|file| b=file.read.split("\r\n").collect{|x| x.match("^.*#{word}$").to_s unless x.match("^.*#{word}$").nil? }.compact } begin #File.open("#{word}.txt","r"){|file| # b=file.read #} #b=b.split("\n") puts "first double loop" (0..2).each{ a={} b.each{|x| x=x.to_s if a[x[x.size-count .. x.size-4]] a[x[x.size-count .. x.size-4]]+=1 else a[x[x.size-count .. x.size-4]]=1 end } count+=1 out.push(a) } puts "remake hash" out2=[] out.flatten! out.each{|hash| tmp_hash={} hash.each{|key,value| puts key tmp_hash[key]=b.collect{|x| x if x.include?(key+"#{word}")}.compact if !key.nil? && key.strip!="" && key.size>2 } out2.push(tmp_hash) } puts "saving" File.open("#{word}_out2.txt","w+"){|file| out2.each{|hash| hash.each{|key,value| file.puts key+"=>["+value*" , " +"]" } } } rescue Exception=>e p e puts e.backtrace end