[comp.unix.xenix.sco] Date Highlighted in SHELL !

cmanis@csoftec.csf.com (Cliff Manis) (09/05/90)

                   Bourne Shell Script  -   HELP needed

Some months ago I got part of this script from the net and have modified
it to highlight the actual date of the month.

At present it will highlight the date if the date is two digit only, and I
have not  been able to make it highlight the first 9 days of the month. We
are using SCO 2.3.1 and any help would be appreciated... 

and Thanks..   Cliff Manis

Please also mail direct to:  cmanis@csoftec.csf.com
---------------------------

# 0datehigh

tmp=month$$
tmp2=newmonth$$
tod=`date +%m`
tod2=`date +%y`
cal $tod 19$tod2 | sed '/^$/d' > $tmp
sed 's/^/                           /' $tmp > $tmp2
tod=`date +%d`
sed 's/'$tod'/'`echo "\033[7m$tod\033[0m"`'/' $tmp2 > $tmp
tod=`date +%y`
sed 's/'$tod'/'`echo "$tod"`'/' $tmp > $tmp2
sed 's/^/'`echo "\033[36m"`'/' $tmp2 > $tmp
tod=`date +%d`
cat $tmp2
rm $tmp $tmp2
# /end of script/

ajm@icc.com (Al Marmora) (09/06/90)

In article <680@csoftec.csf.com> cmanis@csoftec.csf.com (Cliff Manis) writes:
>
>Some months ago I got part of this script from the net and have modified
>it to highlight the actual date of the month.
>
>At present it will highlight the date if the date is two digit only, and I
>have not  been able to make it highlight the first 9 days of the month. We
>are using SCO 2.3.1 and any help would be appreciated... 
>
>and Thanks..   Cliff Manis
>
>Please also mail direct to:  cmanis@csoftec.csf.com
>---------------------------
>

This is what we do here.  You'll have to change the REALCAL= line
to run under Xenix.

Credits: Mike Jenkins <mwj@icc.com> originally developed this script.

#!/bin/sh
#
# cal.sh - highlight today's date if stdout is a terminal
#
# We install this script in /usr/local/bin, which appears
# before /usr/bin in our standard PATH.
#
# 88/12/03 - created (mwj)
# 88/12/19 - fix: don't highlight anything in line 1 (ajm)
# 88/12/19 - fix: highlight only if output is going to a terminal (ajm)
#

REALCAL=/usr/bin/cal

if [ -t 1 -a $# -eq 0 ]
then
	smso=`tput smso`
	rmso=`tput rmso`

	set `date '+%m %d 19%y'`

	day=`echo $2 | sed 's/^0/ /'`
	exec $REALCAL $1 $3 |
	sed -e 's/^/ /' -e "3,\$s/ ${day}/ ${smso}${day}${rmso}/" -e 's/^ //'
else
	exec $REALCAL $*
fi

wnp@iiasa.AT (wolf paul) (09/06/90)

In article <680@csoftec.csf.com> cmanis@csoftec.csf.com (Cliff Manis) writes:
>At present it will highlight the date if the date is two digit only, and I
>have not  been able to make it highlight the first 9 days of the month. We
>are using SCO 2.3.1 and any help would be appreciated... 
>
># 0datehigh
>
>tod=`date +%d`
>sed 's/'$tod'/'`echo "\033[7m$tod\033[0m"`'/' $tmp2 > $tmp

The reason this does not work for single-digit days is simple: date +%d
always produces double-digit output, prepending '0' to the first nine
days of the month. "CAL" does not do this, therefore the "SED" command
cannot find a match.

Anyway, the script below (tested on Ultrix 3.1, SunOS 4.1, ISC SysVr3.2, and
Xenix 286/2.1.3) does the same thing without temp files, just a pipe,
and fewer calls to executables. What is the second string of ANSI
escape sequences in you original script supposed to do?

Before trying it, replace the two occurrences of "^[" with an actual
escape character, entered in vi by typing "Ctrl-V Escape".

#!/bin/sh
# Cal -- display calendar for current month, with month name and
#        today's date highlighted on an ANSI-compatible terminal
#
#        (to be compatible with other terms, the HIGH and LOW strings
#         should be obtained with "tput smso" and "tput rmso" instead
#         of being hardcoded. Since not all UNIXes have tput, this
#         example is hardcoded).
#
set `date "+%d %m 19%y`		# get the three parts of date we want
DAY=$1
MON=$2
YR=$3
HIGH="^[[7m"		# ^[ should be an actual ESCAPE character
LOW="^[[0m"		# ^[ should be an actual ESCAPE character

# System V "pr" has an -o option to produce a page offset, and
# -t option to prevent it from filling one 66-line page with line
# feeds and headers.

# The "sed" script actually is written in two parts, the first part
# double-quoted to permit the interpolation of shell variables,
# and the second part single-quoted to prevent the "1,$s" command in line 6
# to be interpreted as a shell variable "$s".

# Here is what the sed script does (with line numbers):
# 1: delete all blank lines
# 2: append a space to the end of each line, so we can look for each date
#    both preceded and followed by a space
# 3: make all single-digit days double digit by prepending a '0'
# 4: highlight the name of the month and year
# 5: find today's date and highlight it
# 6: now replace all leading zeros with a space, cause it looks better -
#    but only in lines 2ff, we don't want to change the year "2001" into "20 1"

cal $MON $YR | pr -t  -o27 | sed "
/^$/d
s/$/ /
s/ \([1-9]\) /0\1 /g
1s/ \([A-Z][a-z]* [0-9][0-9]*\) / ${HIGH}\1${LOW} /
s/ $DAY / ${HIGH}${DAY}${LOW} /"'
2,$s/0\([1-9]\)/ \1/g' 
# end of "Cal"
-- 
Wolf N. Paul, IIASA, A - 2361 Laxenburg, Austria, Europe
PHONE: +43-2236-71521-465     FAX: +43-2236-71313      UUCP: uunet!iiasa.at!wnp
INTERNET: wnp%iiasa.at@uunet.uu.net      BITNET: tuvie!iiasa!wnp@awiuni01.BITNET
       * * * * Kurt Waldheim for President (of Mars, of course!) * * * *