#!/usr/bin/ruby # Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) # # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to # Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, # 94105, USA. if ARGV.length != 2 $stderr.puts "Usage:\n\t#{$0} (search term) (file with list of terms)\n" exit -1 end term = ARGV[0]; file_name = ARGV[1] line_num = 0 # read in entries & then find all matching entries matching_lines=IO.readlines(file_name).collect{|line|[line_num+=1,line.chomp]}. find_all{|entry|entry[1]==term }.collect{ |entry| entry[0] } # check to see if there are any matching entries if matching_lines.length == 0; puts "Search term not found.\n"; exit -1; end # display lines numbers for the matching entries matching_lines.each { |line| puts "found match on line: #{line}" }