Date Highlighted in SHELL !
wolf paul
wnp at iiasa.AT
Thu Sep 6 19:30:26 AEST 1990
In article <680 at csoftec.csf.com> cmanis at 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 at uunet.uu.net BITNET: tuvie!iiasa!wnp at awiuni01.BITNET
* * * * Kurt Waldheim for President (of Mars, of course!) * * * *
More information about the Comp.unix.xenix.sco
mailing list