# 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 [ $# -ne 2 ]; then echo -e "Usage:\n\t$0 (search term) (file with list of terms)" 2>&1 exit -1 fi search_term=$1; file_name=$2 # prepare egrep search expression - make sure all regex special characters # are escaped search_term=`sed -e 's/\([^0-9]\)/\\\1/g'<<<$search_term` # display line numbers for the matching entries for match in `egrep -n ^$search_term\$ $file_name`; do line_num=`sed -e 's/:.*$//'<<<$match` echo "found on line: $line_num" found_match=1 done # check to see if there were any matches # (/ if we printed out any line numbers in the loop above) if [ ! $found_match ]; then echo "Search term not found." 2>&1; exit -2; fi