1

The input file looks like.

abc=1.01
abc=0.99
abc=2.1
abc=0.9
abc=2.23e-07
abc=1.22

I would like to print the value of abc is less than 1.0. So that output should look like.

abc=0.99
abc=0.9
abc=2.23e-07

However, when I run the code, the last line is absent. Tried as

awk -F '=' '{if($2<1) print $0}' file

awk --version

GNU Awk 3.1.7
10
  • 1
    @msp9011 bc an option?
    – muru
    Jun 18 '19 at 6:43
  • 2
    @msp9011: I'm missing the point probably, but what's wrong with your attempt. You seem to be getting the output as needed?
    – Inian
    Jun 18 '19 at 6:44
  • 2
    I'm confused. Isn't this script doing what you want? 2.23e-07 is less than 2? Also, you can simplify the script to awk -F '=' '$2<1' file.
    – Sparhawk
    Jun 18 '19 at 6:44
  • 1
    stackoverflow.com/a/20684512
    – finswimmer
    Jun 18 '19 at 6:44
  • 1
    @msp9011: Post the awk version you tested this on? It seems to work on GNU awk just fine. May be can you try $2+0 < 1
    – Inian
    Jun 18 '19 at 6:48
0

I think it wll work once you rewrite abc=2.23e-07 to abc=2.23*e-07.

1
  • 2
    You should probably test it too...
    – Kusalananda
    Jun 18 '19 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.