ron@mlfarm.com (Ronald Florence) (01/13/91)
The bsnews (Bootstrap News) package I posted to comp.sources.misc includes an expire command which relies on features of nawk/gawk. I received a number of requests for an old-awk version, including one from Forrie Aldrich (morwyn!forrie), to whom return mail bounces. The old-awk version is ugly, and gawk is widely available, but for anyone who needs it, here is expire.oldawk: #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # /u/src/bsnews/expire.oldawk # This archive created: Mon Jan 7 17:52:21 1991 # By: Ronald Florence (Maple Lawn Farm, Stonington, CT) export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'expire.oldawk'" '(1754 characters)' if test -f 'expire.oldawk' then echo shar: "will not over-write existing file 'expire.oldawk'" else sed 's/^X//' << \SHAR_EOF > 'expire.oldawk' X: X#! /bin/sh X# expire - expires bsnews spool X# copyright 1990 Ronald Florence X# version 1.3 (ron@mlfarm.com, 21 Dec 90) X# X# A version for gawk or nawk would be cleaner; this is portable. X Xwhile [ $# -gt 0 ] X do X case $1 in X -e|-E) shift;; X *) exp=`expr $1 : "-*[eE]*\([0-9]*\)"`; break;; X esac X done X[ -z "$exp" ] && { echo "usage: $0 days"; exit; } X XNewsspool=NEWSSPOOL XTimestamp=`ls -l $Newsspool | awk ' X BEGIN { X month["Jan"] = 1 X month["Feb"] = 2 X month["Mar"] = 3 X month["Apr"] = 4 X month["May"] = 5 X month["Jun"] = 6 X month["Jul"] = 7 X month["Aug"] = 8 X month["Sep"] = 9 X month["Oct"] = 10 X month["Nov"] = 11 X month["Dec"] = 12 X } X { split($8, time, ":") X printf "%02d%02d%02d%02d", month[$6], $7, time[1], time[2] X }'` XTmpspool=/tmp/expire.$$ Xtrap 'rm -f $Tmpspool' 1 2 3 15 X Xawk ' XBEGIN { X month["Jan"] = 1 X month["Feb"] = 2 X month["Mar"] = 3 X month["Apr"] = 4 X month["May"] = 5 X month["Jun"] = 6 X month["Jul"] = 7 X month["Aug"] = 8 X month["Sep"] = 9 X month["Oct"] = 10 X month["Nov"] = 11 X month["Dec"] = 12 X expired = 0 X expdays = '`echo $exp`' X split ("'"`date`"'", now) X split("31 28 31 30 31 30 31 31 30 31 30 31", days) X n = (now[6] - 1901) * 365 + int((now[6] - 1901) / 4) X if (now[6] % 4 == 0) X days[2]++ X for (i = 1; i < month[now[2]]; i++) X n += days[i] X zap = n + now[3] - expdays X} X X/^From / && expired == 0 { X split("31 28 31 30 31 30 31 31 30 31 30 31", days) X n = ($7 - 1901) * 365 + int(($7 - 1901) / 4) X if ($7 % 4 == 0) X days[2]++ X for (i = 1; i < month[$4]; i++) X n += days[i] X if (n + $5 > zap) X expired = 1 X} Xexpired == 1 { print $0 } X' < $Newsspool > $Tmpspool X Xtouch $Timestamp $Newsspool Xmv $Tmpspool $Newsspool X SHAR_EOF if test 1754 -ne "`wc -c < 'expire.oldawk'`" then echo shar: "error transmitting 'expire.oldawk'" '(should have been 1754 characters)' fi fi exit 0 # End of shell archive -- Ronald Florence ron@mlfarm.com