Created
March 14, 2010 13:37
-
-
Save mathfur/331974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 指定のパス下にあるファイルから/w+を取り出して | |
# 単語\t絶対パス\t行番号 | |
# のファイルを生成する | |
require "digest/md5" | |
paths = ["C:/usr/examples"] | |
exts = %w{ps1} | |
$verbose = false | |
paths.each do |path| | |
results_before_digest = [] | |
Dir.glob("#{path}/**/*.{#{exts.join(",")}}") do |fn| | |
STDERR.puts ">>#{fn}を検索" if $verbose | |
File.read(fn).each_with_index do |line,num| | |
line.scan(/[a-zA-Z0-9]+/) do |w| | |
results_before_digest << [w,File.expand_path(fn),num] | |
end | |
end | |
end | |
results_after_digest = results_before_digest. | |
map{|w,_,__| [Digest::MD5.hexdigest(w),_,__]}.sort_by{|a,b,c| a.to_i(16)} | |
open("#{path}/after_digest.txt","w") do |f| | |
f.puts results_after_digest.map{|e| e.join("\t")} | |
end | |
open("#{path}/before_digest.txt","w") do |f| | |
f.puts results_before_digest.map{|e| e.join("\t")} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment