For Programmers: Free Programming Magazines  


Home > Archive > AWK > July 2006 > matching pattern problem with decimal numbers









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author matching pattern problem with decimal numbers
kamal.pdoc@gmail.com

2006-07-21, 7:56 am

I need to check if in a line of many columns if column 9 has values
like 2.10, 2.30 etc. and if yes then print them in a file. I tried the
following (and some other commands) for a source file like "pure_tf.tr"

cat pure_tf.tr | grep "^r" | grep "1 0 exp" | awk '{ if ($9==/2./)
print}'

But it doesn't seem to work. My problem is to figure out how to compare
decimal numbers..?? Please advice. (Mean while I continue to look)

Thank you.

Chris F.A. Johnson

2006-07-21, 6:56 pm

On 2006-07-21, kamal.pdoc@gmail.com wrote:
> I need to check if in a line of many columns if column 9 has values
> like 2.10, 2.30 etc. and if yes then print them in a file. I tried the
> following (and some other commands) for a source file like "pure_tf.tr"
>
> cat pure_tf.tr | grep "^r" | grep "1 0 exp" | awk '{ if ($9==/2./)
> print}'
>
> But it doesn't seem to work. My problem is to figure out how to compare
> decimal numbers..?? Please advice. (Mean while I continue to look)


grep "^r.*1 0 exp" pure_tf.tr | awk '$9 ~ /^2\.[0-9]*$/ { print $0 }'

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com