summaryrefslogtreecommitdiff
path: root/merge_files
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2013-12-05 07:56:38 +0100
committerPatrick Simianer <p@simianer.de>2013-12-05 07:56:38 +0100
commitdb6a6ecfa350cae29739c59df1210d8f76a479c9 (patch)
treef137a001f57f170455c28ce97b5abb2726006cf6 /merge_files
init
Diffstat (limited to 'merge_files')
-rwxr-xr-xmerge_files32
1 files changed, 32 insertions, 0 deletions
diff --git a/merge_files b/merge_files
new file mode 100755
index 0000000..db9d5da
--- /dev/null
+++ b/merge_files
@@ -0,0 +1,32 @@
+#!/usr/bin/env ruby
+
+STDOUT.set_encoding 'utf-8'
+
+def usage
+ STDERR.write "merge_files [file]+\n"
+ exit 1
+end
+usage if ARGV.size==0
+
+
+files = ARGV
+dicts = []
+
+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
+ end
+}
+
+dicts.each { |h|
+ h.each { |k,v|
+ counts = []
+ dicts.each { |j| counts.push j[k]; j.delete k }
+ counts.max.times { puts k }
+ }
+}
+