diff options
author | Patrick Simianer <p@simianer.de> | 2014-01-29 19:14:08 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-01-29 19:14:08 +0100 |
commit | 68acbb9a0c7967cb90a7e3756fc94fdd8a73d154 (patch) | |
tree | 3b445131dcb203e94473ae1d8aa82a1798585276 /merge_files | |
parent | 49158e721bfaf6423dca9fc633873218f691c83a (diff) |
make use of nlp_ruby, LICENSE
Diffstat (limited to 'merge_files')
-rwxr-xr-x | merge_files | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/merge_files b/merge_files index db9d5da..051ad6d 100755 --- a/merge_files +++ b/merge_files @@ -1,31 +1,31 @@ #!/usr/bin/env ruby -STDOUT.set_encoding 'utf-8' +require 'nlp_ruby' + def usage - STDERR.write "merge_files [file]+\n" + STDERR.write "merge_files <file>+\n" exit 1 end usage if ARGV.size==0 - files = ARGV -dicts = [] +hashes = [] files.each { |i| - dicts.push Hash.new - dicts.last.default = 0 - File.open i, "r:UTF-8" do |f| - while line = f.gets - dicts.last[line.strip] += 1 - end + hashes.push Hash.new + hashes.last.default = 0 + f = ReadFile.new i + while line = f.gets + hashes.last[line.strip] += 1 end + f.close } -dicts.each { |h| +hashes.each { |h| h.each { |k,v| counts = [] - dicts.each { |j| counts.push j[k]; j.delete k } + hashes.each { |j| counts.push j[k]; j.delete k } counts.max.times { puts k } } } |