#!/usr/bin/env perl # 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 != 1) { print stderr "Usage:\n\t$0 (search term) (file with list of terms)\n"; exit -1; } $term = $ARGV[0]; $file_name = $ARGV[1]; # read in the entries open fh, $file_name or die "Can't open '$file_name'\n"; @entries = map { chomp $_; [$idx++, $_] } ; close fh; # find all matching entries @matching_entries = grep {$_->[1] eq $term} @entries; # check to see if there are any matching entries if ($#matching_entries == -1) { print "Search term not found.\n"; exit; } # display line numbers for the matching entries foreach $entry (@matching_entries) { print "found match on line: ",($entry->[0]+1),"\n"; }