[PLUG] awk syntax error, part ii
Larry Brigman
larry.brigman at gmail.com
Fri May 25 19:03:41 UTC 2012
On Fri, May 25, 2012 at 11:53 AM, Larry Brigman <larry.brigman at gmail.com> wrote:
> On Fri, May 25, 2012 at 11:48 AM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
>> On Fri, 25 May 2012, Larry Brigman wrote:
>>
>>> I think your problem lies at the end of each if or else if statement
>>> as you have
>>> a semi-colon which terminates the operation. You can move the semi-colon
>>> to inside the } or remove it altogether.
>>
>> awk: ./zero-to-rl.awk:17: else if ($3 ~ /Se/ && $4 ~ /0.000/) { print $1,
>> $2, $3, "-0.003" }
>> awk: ./zero-to-rl.awk:17: ^ syntax error
>> awk: ./zero-to-rl.awk:18: else if ($3 ~ /TDS/ && $4 ~ /0.000/) { print $1,
>> $2, $3, "-15.000" }
>> awk: ./zero-to-rl.awk:18: ^ syntax error
>> awk: ./zero-to-rl.awk:19: else { print $1, $2, $3, $4 }
>> awk: ./zero-to-rl.awk:19: ^ syntax error
>>
>> No semi-colons at the end, same syntax error indication.
>>
>> Putting semi-colons inside the closing brace still yields the same syntax
>> error indication.
>>
>> Thanks,
>>
>> Rich
>>
> Can you post enough of the data to debug this?
Never mind.
You are trying to parse on fields when the fields have not been parsed yet.
add {
} around your whole conditional list like:
{if ....... else ...... }
and move your semi-colons inside the { } for the conditions action.
Here is the code that executes (or at least doesn't throw syntax errors.
---------------------------
#! /usr/bin/awk -f
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 }
}
More information about the PLUG
mailing list