I am attempting to keep track of the lowest/highest values from a list of counties and populations.  I can't figure out how to stop variables from resetting themselves at 0.  This is my cmd.awk file.BEGIN {    FS=\t    HPD=0    HPDname=    LPD=0    LPDname=    HPW=0    HPWname=    LPW=0    LPWname=}# Stuff in here needs to be printed during the process.{  print $1  PD=$2/$4  print PD  PW=($3/($3+$4))*100  print PW# These if statements see if there is a new highest or lowest value for the     categories.  if ($PD>$HPD)  {    HPD=$PD    HPDname=$1  }  if ($PD<$LPD)  {    LPD=$PD    LPDname=$1  }  if ($PW>$HPW)  {    HPW=$PW    HPWname=$1  }  if ($PW<$LPW)  {    LPW=$PW    LPWname=$1  }}# Prints off all of the ending information that we have been keeping track      of.END {    print The highest population density: $HPDname $HPD    print The lowest population density: $LPDname $LPD    print The highest percentage of water: $HPWname $HPW    print The lowest percentage of water: $LPWname $LPW}The output of END always shows the last county to be analyzed instead of keeping track of the highest or lowest.
How do I keep awk variables in scope?
awk
To clarify what the commenters noted in code:BEGIN {    FS=\t    HPD=0    HPDname=    LPD=0    LPDname=    HPW=0    HPWname=    LPW=0    LPWname=}# Stuff in here needs to be printed during the process.{  print $1  PD=$2/$4  print PD  PW=($3/($3+$4))*100  print PW# These if statements see if there is a new highest or lowest value for the     categories.  if (PD>HPD)  {    HPD=PD    HPDname=$1  }  if (PD<LPD)  {    LPD=PD    LPDname=$1  }  if (PW>HPW)  {    HPW=PW    HPWname=$1  }  if (PW<LPW)  {    LPW=PW    LPWname=$1  }}# Prints off all of the ending information that we have been keeping track      of.END {    print The highest population density: HPDname HPD    print The lowest population density: LPDname LPD    print The highest percentage of water: HPWname HPW    print The lowest percentage of water: LPWname LPW}You're mixing up Bash like variable syntax and awk.Bash:variable='something'echo $somethingawk:variable=somethingprint variableawk uses $ for the field variables, like $1, $2, $0, $NF, but NOT for variables you have created. I think that's more or less right technically though I have to admit I never read up on the specifics.variable assignment