Skip to content

Instantly share code, notes, and snippets.

@mathfur
Created March 14, 2010 13:37
Show Gist options
  • Save mathfur/331974 to your computer and use it in GitHub Desktop.
Save mathfur/331974 to your computer and use it in GitHub Desktop.
# 指定のパス下にあるファイルから/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