mp (05/19/82)
#! /bin/sh
:
:
: shell script that if run on a census report will print
: the census report with
:
: 1 the total population in that sector
:
: 2 the minimum amount of food for that sector for a day
:
: 3 an asterisk at the end of the line if that sector is too low
:
: 4 a < at the end of the line if sector not self-sustaining in food
:
: based on duke!decvax!ucbvax!ucsfcgl!sdcarl!rusty Thu May 13 18:39:30 1982
: M. Pique version 2. Handles checkpointed and defended sectors.
: Defaults to reading file 'census' in current directory
if test $# -lt 1
then
if test -r census
then
exec $0 census
else
echo "usage: $0 census1 census2 ..."
exit 1
fi
fi
for file
do
awk ' / sect / { print $0 " pop minf warn" ;next }
NF>11{ # non-header non-trailer lines:
cfield= NF-6 # field giving number of civilians
civ = $(cfield)
mil = $(cfield+1)
food = $(cfield+2)
fert = $(cfield+5)
pop = civ + mil
minf = pop * 0.048
if ( minf < 1 )
minf = 1
if ( food < minf ) warn = "*"
else warn = " "
if( mil > 1.66 * civ || pop > 2*fert ) alert = "<"
else alert = " "
printf "%s %3d %4.0f %s%s\n", $0, pop, minf, warn, alert
next
}
{ print $0;next }
END { print " * -- low food reserves < -- not self-sustaining"}
' $file
done