#!/bin/csh -f # search # ----------------------------------------------------------------------------- # Shell script to search a file for a string. # ----------------------------------------------------------------------------- # Usage: See Usage section below or run with no arguments to see usage. # Assumptions: # Effects: # - Echos matches to stdout # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ----------------------------------------------------------------------------- if ($#argv == 0 || "$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [options] matchstring [input_file]" echo "Where options can be any of the following:" echo " -i = Ignore case" echo " -H = Highlight matches" echo " -h = Show this help text" echo " --help = Show this help text" exit 1 endif # Collect command line options set ignore_case_option = "" set highlight_option = "false" while ($#argv > 0) if ("$1" == "-i") then # Ignore case set ignore_case_option = "$1" shift else if ("$1" == "-H") then set highlight_option = "true" shift else # Not a recognized option. Assume it's the filename pattern. break endif end if ($highlight_option == "true") then # Search silently to see if any matches java -classpath /Users/fred/fred/lib/search.jar:/Users/fred/fred/lib/bristle.jar com.bristle.javaapps.search.SearchWithContext ${ignore_case_option} $*:q > /dev/null set rc = $status if ($rc == 0) then # Matches found. Pipe through less with highlighting of matches. # +/$1:q = Search for specified string # -I = Ignore case # -+F = Don't exit less even if output fits on screen. This is # because less may have jumped ahead to the first match and # not counted the earlier text of a long paragraph as needing # to fit on the screen. java -classpath /Users/fred/fred/lib/search.jar:/Users/fred/fred/lib/bristle.jar com.bristle.javaapps.search.SearchWithContext ${ignore_case_option} $*:q | less -I -+F +/$1:q endif set rc = $status else java -classpath /Users/fred/fred/lib/search.jar:/Users/fred/fred/lib/bristle.jar com.bristle.javaapps.search.SearchWithContext ${ignore_case_option} $*:q | less set rc = $status endif exit $rc