Highlighted output from shell script?

Daniel Ray norstar at tnl.UUCP
Thu Feb 1 17:13:58 AEST 1990


> ...
> Well, here's mon, my version of cal.  It works on both the SYSV AND BSD systems
> that I've tried it on.  It even deals with pad characters (termcap).
> 
> It expects the termcap entry to be in the $TERMCAP variable for BSD.
> 
> 	-Jeff
> ...

Why do something just for 'cal' when you can solve the problem once and for
all, UNIX-style?! Below is a highlighting/colorizing search filter that
can be used with both cal or any other strings...

--------------------------start search shell script----------------------------
:
# @(#) search v1 12/04/89 by Daniel Ray
# The Northern Lights (TNL v2) Burlington, Vermont
# RELEASED INTO THE PUBLIC DOMAIN FOR UNREGULATED DISTRIBUTION
#
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#
# SEARCH: highlights search expression via sed, can be used with grep
# CAUTION: requires compatible terminal whos highlight/colorization data is
#  available via 'tput' (TERMINFO database). Presumes the availability of
#  the 'setcolor' utility.
#
# Usage: search 'string' < /file/name          (highlights string)
#	 prog | search 'string'                (highlights string)
#        search 'string' /file/name            (highlights string)
#        prog | search -l 'string'	       (highlights whole line)
#
#        prog | search color1 color2 'string'  (uses color instead of inv vid.
#                                               Sets foreground color only.
#                                               'color2' arg should be the
#                                               CURRENT foreground color in
#                                               in use prior to using search)
#
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#
case "$3" in
"") ;;
*) smso=`/usr/bin/setcolor $1` ; rmso=`/usr/bin/setcolor $2`
shift ; shift ; /bin/sed "s/$1/${smso}$1${rmso}/g" $2 ; exit 0 ;;
esac
smso=`/usr/bin/tput smso 2>/dev/null | /bin/tr "&" "="`
rmso=`/usr/bin/tput rmso 2>/dev/null | /bin/tr "&" "="`
case "$1" in
-l) shift ; /bin/sed "s/^.*$1.*$/${smso}&${rmso}/" $2 ; exit 0 ;;
-?*) /bin/echo "\nSEARCH TEXT HIGHLIGHTIMG Options\n
search 'string' filename		(highlights string in file)
search -l 'string' filename		(highlights line in file)
search color1 color2 'string' filename  (color1=foreground color highlighting)
prog | search 'string'			(piped output)
prog | search -l 'string'		(piped output, highlights whole line)
prog | search color1 color2 'string'    (piped color output)\n" ; exit 2 ;;
esac
case "$*" in
"") /bin/echo "Usage: $0 [-l] 'string' [filename]" >&2 ; exit 1 ;;
*) /bin/sed "s/$1/${smso}$1${rmso}/g" $2 ;;
esac
-------------------------end search shell script------------------------------

norstar
The Northern Lights, Burlington Vermont             |      Still
tnl dialins: 802-865-3614 at 1200-2400 bps.       ` | /      here
-------------------------------------------     --- * ---      but
uucp: uunet!uvm-gen!tnl!norstar or                / | .       fading
{decvax,linus}!dartvax!uvm-gen!tnl!norstar          |        fast!



More information about the Comp.unix.questions mailing list