#!/bin/sh
## The awkscr variable is set to the entire awk script. This allows 
## the awk script to be included in the awk command later on in the 
## shell script. The awk script can be included directly after the 
## awk command. The method shown is used ONLY to make the overall 
## UNIX script more readable. The awk script finds the maximum depth 
## in the EPA-SWMM output file. This script finds the first local
## maximum, and prints the basin name and the maximum value on stdout.

awkscr=' {
  if ( old < new || ( old == 0 && new == 0 ) ) { 
     old = new
     new = $2
  }
  else {
     print $1, old
     exit
  }
}'

## The for loop goes through the basin names one by one. Only a part 
## of one for loop is shown here for illustration. The grep command 
## finds every line the basin name is mentioned and pipes the list 
## to the awk command with the script from above. The result is a 
## single line printed out showing the basin name and the maximum 
## value.
for basin in DSEU001 DSEU002 DSEU003 DSEU004 DSEU005 DSEU006 
do
     grep "$basin" depthds100.out | awk "$awkscr"
done