rusty (05/14/82)
Here is a shell script that if run on a census report will print
the census report with
(1) the total population in that census
(2) the minimum amount of food for that census for a day
(3) an asterisk at the end of the line if that census is too low
Here it is:
#! /bin/sh
if test $# -lt 1
then
echo "usage: famine census1 census2 ..."
exit 1
fi
for file
do
cat $file | awk ' { if ( NR < 3 ) print }
{ if ( NR == 3 ) print $0 " pop minf" }
{ if ( NR > 3 ) {
pop = $7 + $8
minf = pop * 0.048
if ( minf < 1 )
minf = 1
warn = ""
if ( $9 < minf )
warn = "*"
printf "%s %3d %4.0f %s\n", $0, pop, minf, warn
} } '
done
rusty (05/14/82)
The "cat" is unnecessary:
#! /bin/sh
: famine is a widget for empire.
: given a census report from empire
: it prints the population per sector
: along with the minimum amount of
: food necessary for that sector.
: sectors that are below this minimum
: are flagged with an asterisk.
if test $# -lt 1
then
echo "usage: famine census1 census2 ..."
exit 1
fi
for file
do
awk ' { if ( NR < 3 ) print }
{ if ( NR == 3 ) print $0 " pop minf" }
{ if ( NR > 3 ) {
pop = $7 + $8
minf = pop * 0.048
if ( minf < 1 )
minf = 1
warn = ""
if ( $9 < minf )
warn = "*"
printf "%s %3d %4.0f %s\n", $0, pop, minf, warn
} } ' $file
done
rusty (05/14/82)
haste makes waste. in my first message /([1-3])/s/census/sector/
rusty (05/27/82)
Here is a famine that is a merge of the features of my previous one and the one from unc!mp. #! /bin/sh : famine is a widget for empire. : given a census report from empire : it prints the minimum amount of : food necessary for each sector and : the difference between what is there : and should be there. sectors that are : below the minimum are flagged with : an asterisk '*', sectors that are not : self sustaining are flagged with a : tilde '~'. : these magic numbers were gleaned : from "info food" and "info innards", : they may need to be changed. eatrate=0.048 fcrate=1.666 exec awk " { if ( ( \$1 == \"sect\" ) && ( \$2 == \"eff\" ) && ( \$3 == \"mob\" ) ) print \$0 \" minf fdiff\" else if ( ( \$1 ~ /[0-9],/ ) && ( \$3 ~ /[0-9]%\$/ ) ) { cfield = NF-6 # field giving number of civilians civ = \$(cfield) mil = \$(cfield+1) food = \$(cfield+2) fert = \$(cfield+5) pop = civ + mil minf = pop * ${eatrate} if ( minf < 1 ) minf = 1 fdiff = food - minf + 0.5 alert = \" \" if ( ( mil > ${fcrate} * civ ) || ( pop > 2 * fert ) ) alert = \" ~\" warn = \"\" if ( food < minf ) warn = \"*\" printf \"%s %4.0f %5d%s%s\n\", \$0, minf, fdiff, alert, warn } else print } " ${@}