[PLUG] awk syntax error, part ii

Rich Shepard rshepard at appl-ecosys.com
Fri May 25 20:18:54 UTC 2012


On Fri, 25 May 2012, Larry Brigman wrote:

> Can you post enough of the data to debug this?

Larry,

   Here's a sample:

'A'|'1987-12-12'|'Ag'|0.000|
'A'|'1987-12-12'|'Al'|0.106|
'A'|'1987-12-12'|'CO3'|-1.000|
'A'|'1987-12-12'|'HCO3'|231.000|
'A'|'1987-12-12'|'Alk_tot'|231.000|
'A'|'1987-12-12'|'As'|0.011|
'A'|'1987-12-12'|'Ba'|0.000|
'A'|'1987-12-12'|'Be'|-0.002|
'A'|'1987-12-12'|'Bi'|0.000|
'A'|'1987-12-12'|'Ca'|100.000|
'A'|'1987-12-12'|'Cd'|0.000|
'A'|'1987-12-12'|'Cl'|1.430|
'A'|'1987-12-12'|'Co'|0.000|
'A'|'1987-12-12'|'Cr'|-0.006|
'A'|'1987-12-12'|'Cu'|0.024|

   There are 5 rows with 0.000 in the fourth field.

   And, here's the script:

#! /usr/bin/awk -f

# zero-to-rl.awk

BEGIN { FS = "|"; OFS = "|"}

if ($3 ~ /Ag/ && $4 ~ /0.000/) { print $1, $2, $3, "-0.005" }
else if ($3 ~ /Alk_tot/ && $4 ~ /0.000/) { print $1, $2, $3, "-1.000" }
else if ($3 ~ /Cr/ && $4 ~ /0.000/) { print $1, $2, $3, "-0.030" }
else if ($3 ~ /Fe/ && $4 ~ /0.000/) { print $1, $2, $3, "-1.200" }
else if ($3 ~ /Mg/ && $4 ~ /0.000/) { print $1, $2, $3, "-1.000" }
else if ($3 ~ /NO3-NO2/ && $4 ~ /0.000/) { print $1, $2. $3, "-0.020" }
else if ($3 ~ /Na/ && $4 ~ /0.000/) { print $1, $2, $3, "-0.530" }
else if ($3 ~ /Sb/ && $4 ~ /0.000/) { print $1, $2, $3, "-0.010" }
else if ($3 ~ /Se/ && $4 ~ /0.000/) { print $1, $2, $3, "-0.003" }
else if ($3 ~ /TDS/ && $4 ~ /0.000/) { print $1, $2, $3, "-15.000" }
else { print $1, $2, $3, $4 }

Thanks,

Rich




More information about the PLUG mailing list