1829590 Members
8211 Online
109992 Solutions
New Discussion

AWK Help Please.

 
SOLVED
Go to solution
fg_1
Trusted Contributor

AWK Help Please.

 
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: AWK Help Please.

I suspect you meant

if [ ${STAT} -eq 0 -o ${STAT} -eq 1 ]
then

fi

Better still
if [[ ${STAT} -eq 0 || ${STAT} -eq 1 ]]
then

fi
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: AWK Help Please.

Hi Frank:

# if [ "$status" = 1 -o "$status" = 2 ]

Regards!

...JRF...
fg_1
Trusted Contributor

Re: AWK Help Please.

Thank you clay,

when i tried your statement change for the if statement this is the output that i get:if [[ ${status} -eq 0 || ${status} -eq 1 ]]
then
status="$status";
else
status="$status";
fi

printf("%s%s%s%s%s%s%s%s%s%s\n",jobid,sta,
Kbytes,files,compestimated);
}' > ${TMP_FILE}
syntax error The source line is 17.
The error context is
if >>> [ <<< [ ${status} -eq 0 || ${status} -eq 1 ]]
awk: The statement cannot be correctly parsed.
The source line is 17.
syntax error The source line is 19.

Is there something like maybe a ; that has to go at the end of the if,then,else statements since its located in the middle of an AWK statement?

Andreas Voss
Honored Contributor

Re: AWK Help Please.

Hi,

the lines:
if [ $status is "0 or 1" ] ; then
status="$status";
else
status="$status";
fi

are shell-script-like.

When you want this in awk it should be:

if(status == "0" || status == "1)
status="" status "";
else
status="" status "";

Regards
Andreas Voss
Honored Contributor

Re: AWK Help Please.

Oh sorry,

i've missed a quote:

if(status == "0" || status == "1")
James R. Ferguson
Acclaimed Contributor

Re: AWK Help Please.

Hi (again) Frank:

Oops, I missed that fact that it was part of the 'awk'. Therefore:

# {if ($status==0 || $status==1) {...} else {...}}

Regards!

...JRF...
fg_1
Trusted Contributor

Re: AWK Help Please.

Ok all

Each of these suggestions has been very helpful, but I must be missing something since I am still getting this message:

if ($status==0 || $status==1);
then
status="$status";
else
status="$status";
fi

printf("%s%s%s%s%s%s%s%s%s%s\n",jobid,sta,
Kbytes,files,compestimated);
}' > ${TMP_FILE}
syntax error The source line is 20.
The error context is
>>> else <<<
awk: The statement cannot be correctly parsed.
The source line is 20.


Does the ELSE statement have a problem the way it is or do I have to do a else; ? or am I looking in the wrong place.

A. Clay Stephenson
Acclaimed Contributor

Re: AWK Help Please.

Okay, I throughly confused. Is this shell or awk? I thought that your original if was shell that was calling some awk. If it is awk, then
drop the '$', it should be simply 'status' rather than '$status'. (I know you use $1,$2, ... but this is awk; you want consistancy?)

also you need to watch semicolons;

if (status == 0 || status == 1); <-- WRONG; no semicolon

AND

= is an assignment; == is a comparison
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: AWK Help Please.

Hi (again) Frank:

Note again:

{if ($status==0 || $status==1) {...} else {...}}

There is no "then" word in 'awk'...

Regards!

...JRF...