Skip to content

Instantly share code, notes, and snippets.

@rklemme
Created October 19, 2011 07:34
Show Gist options
  • Save rklemme/1297678 to your computer and use it in GitHub Desktop.
Save rklemme/1297678 to your computer and use it in GitHub Desktop.
#!/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