using awk with column value conditions

前端 未结 6 502
甜味超标
甜味超标 2020-11-29 18:10

I\'m learning awk from The AWK Programming Language and I have a problem with one of the examples.

If I wanted to print $3 if $2 is equal to a value (e.g.1

6条回答
  •  旧巷少年郎
    2020-11-29 18:58

    My awk version is 3.1.5.

    Yes, the input file is space separated, no tabs.

    According to arutaku's answer, here's what I tried that worked:

    awk '$8 ~ "ClNonZ"{ print $3; }' test  
    0.180467091
    0.010615711
    0.492569002
    
    
    $ awk '$8 ~ "ClNonZ" { print $3}' test  
    0.180467091
    0.010615711
    0.492569002
    

    What didn't work(I don't know why and maybe due to my awk version:),

    $awk '$8 ~ "^ClNonZ$"{ print $3; }' test
    $awk '$8 == "ClNonZ" { print $3 }' test
    

    Thank you all for your answers, comments and help!

提交回复
热议问题