|
Prev: seperating parametrs in loop other then space
Next: how to find the second column is a digital number and biger than 50000
From: robertchen117 on 12 Apr 2008 03:21 I have a file, like this: host1 52233 host2 failed scan host3 2333 I want to get all these second column is a digital number and biger than 50000, please let me how to do it. if I use the following command, it will get "failed" hosts also. cat host_file | nawk '{if($2 >=50000){print $1, $2}}' So how to check if the column is a digital number...? Please help me.
From: pk on 12 Apr 2008 04:57 robertchen117(a)gmail.com wrote: > I have a file, like this: > > host1 52233 > host2 failed scan > host3 2333 > > I want to get all these second column is a digital number and biger > than 50000, please let me how to do it. > > if I use the following command, it will get "failed" hosts also. > cat host_file | nawk '{if($2 >=50000){print $1, $2}}' > > So how to check if the column is a digital number...? Please help me. awk '($2~/[[:digit:]]+/) && ($2 >=50000)' host_file or awk '($2!~/failed/) && ($2 >=50000)' host_file -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome.
From: pk on 12 Apr 2008 06:02 Janis Papanagnou wrote: > awk '0 + $2 >= 50000 {print $1, $2}' hostfile This is what I thought at first too, but if the file is host1 52233 host2 51000failed scan host3 2333 awk prints the second line too. I guess that's because the standard says that string->number conversions should behave as in atof(). -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome.
From: pk on 12 Apr 2008 06:04
pk wrote: > awk '($2~/[[:digit:]]+/) && ($2 >=50000)' host_file This should actually be awk '($2~/^[[:digit:]]+$/) && ($2 >=50000)' host_file -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome. |