#!/bin/sh ################################################# ## hl v1.1 ## ## display a matched pattern in reverse text ## ## hl is an acronym for HighLight ## ## ## ## documentation at: ## ## http://Business-PHP.com/opensource/hl/ ## ## ## ## Copyright (c) 15 May 2003 Atom Emet ## ## Atom*Business-PHP.com ## ## ## ## This program is free software; you can ## ## redistribute it and/or modify it under the ## ## terms of the GNU General Public License as ## ## published by the Free Software Foundation; ## ## either version 2 of the License, or ## ## (at your option) any later version. ## ## ## ## This program is distributed in the hope ## ## that it will be useful, but WITHOUT ANY ## ## WARRANTY; without even the implied warranty ## ## of MERCHANTABILITY or FITNESS FOR A ## ## PARTICULAR PURPOSE. See the GNU General ## ## Public License for more details. ## ## ## ## You should have received a copy of the ## ## GNU General Public License along with this ## ## program; if not, write to ## ## the Free Software Foundation, Inc. ## ## 59 Temple Place - Suite 330 ## ## Boston, MA 02111-1307, USA ## ################################################# ####################################### ## allow either one or two arguments ## ####################################### if [ "${#}" -gt '2' ] || [ "${#}" -eq '0' ] || [ ! "${1}" ] then ################################################# ## if the wrong number of arguments are given, ## ## echo an error message into STANDARD ERROR ## ## and exit leaving an exit status "1" ## ################################################# echo "hl: usage:" >&2 echo " hl '[pattern]' [file]" >&2 echo " -- or --" >&2 echo " command | hl '[pattern]'" >&2 exit 1 fi ########################################################### ## check if a file argument is given on the command line ## ########################################################### if [ "${#}" = '2' ] then ######################################################## ## if there's an argument, check that the file exists ## ######################################################## if [ -e "${2}" ] then ########################################################### ## if the file specified on the command line does exist, ## ## input comes from that file ## ########################################################### pattern1=`echo "${1}" | sed 's,/,\\\/,g'` pattern2=`printf '\033[7m&\033[0m'` sed "s/${pattern1}/${pattern2}/g" "${2}" exit 0 else ############################################################### ## if the file specified on the command line does not exist, ## ## echo an error message into STANDARD ERROR ## ## and exit leaving an exit status "2" ## ############################################################### echo "hl: No such file or directory \"${2}\"" >&2 exit 2 fi else ################################################## ## if no file is specified on the command line, ## ## then input comes from STANDARD INPUT ## ################################################## pattern1=`echo "${1}" | sed 's,/,\\\/,g'` pattern2=`printf '\033[7m&\033[0m'` sed "s/${pattern1}/${pattern2}/g" exit 0 fi