Created
October 19, 2011 07:34
-
-
Save rklemme/1297678 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby19 | |
require 'set' | |
keys = File.read(ARGV.shift).scan(/\w+/).to_set | |
index = Hash.new {|h,word| h[word] = Set.new} | |
ARGF.each do |line| | |
line.scan /\w+/ do |word| | |
index[word].add ARGF.lineno if keys.include? word | |
end | |
end | |
keys.sort.each do |word| | |
puts word, index[word].sort.join(', ') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment