summaryrefslogtreecommitdiff
path: root/merge_files
blob: 0b4941e2ed2310f49a2ffa4cd46e884a545b186e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ruby

require 'zipf'


def usage
  STDERR.write "merge_files <file>+\n"
  exit 1
end
usage if ARGV.size==0

files = ARGV
hashes = []

files.each { |i|
  hashes.push Hash.new
  hashes.last.default = 0
  f = ReadFile.new i
  while line = f.gets
    hashes.last[line.strip] += 1
  end
  f.close
}

hashes.each { |h|
  h.each { |k,v|
    counts = []
    hashes.each { |j| counts.push j[k]; j.delete k }
    counts.max.times { puts k }
  }
}