1848609 Members
6701 Online
104033 Solutions
New Discussion

awk help

 
SOLVED
Go to solution
someone_4
Honored Contributor

awk help

Hello everyone ,

I have an awk one liner here.

cat file.out | awk '{if ($3 < "30.00") print $1,$3}'

And I am getting this out put.

cdrdbs241 29.70
datadbs001 26.98
llogdbs001 0.00
llogdbs002 0.00
llogdbs003 0.00
llogdbs004 0.00
llogdbs005 0.00
llogdbs006 0.00
llogdbs007 0.00
llogdbs008 0.00
llogdbs009 0.00
llogdbs010 0.00
llogdbs011 0.00
llogdbs012 0.00
physdbs 0.00
pindbs001 100.00
pindbs002 100.00
pindbs003 100.00
pindbs004 100.00
pindbs005 100.00
pindbs006 100.00
pinfk1dbs001 100.00
pinfk2dbs001 100.00
pinfk3dbs001 100.00
pinfk4dbs001 100.00
pinidx1dbs001 100.00
pinidx2dbs001 100.00
pinidx3dbs001 100.00
pinpkdbs001 100.00
tgudbs001 29.95

I cant figure out why I am getting back 100.

Richard
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: awk help

Your are doing string comparisons. Change to $3 + 0 < 30. The + 0 forces a numeric context.
If it ain't broke, I can fix that.
harry d brown jr
Honored Contributor

Re: awk help

get rid of the quotes around 30.00.

live free or die
harry
Live Free or Die
someone_4
Honored Contributor

Re: awk help

Both of the solutions worked for me. I am not sure where I picked up the " " around the number. Is that a bad habbit that I need to get rid of?

Mr. Clay can you tell me more about the +0 and what the difference is with the +0 and with out it.

Thanks

Richard
harry d brown jr
Honored Contributor

Re: awk help

Richard,

The adding of ZERO (0) to a string causes "normalization". Now this won't work in languages like C or C++, but it does the job in awk.

awk '{if ($3 < ("30.00" + 0)) print $1,$3}'


live free or die
harry
Live Free or Die