#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    UK
    Posts
    196
    Rep Power
    15

    Awk - testing field values


    I want to search a large file for particular data and so used the awk command.

    I want to understand how the various conditions work with the fields.
    e.g.
    Code:
    awk -F, '$10>1, $3=="FIELD"{print $1"."$2}' data.txt
    The file is a comma separated, but not all records have 10 fields, is this a problem?

    The awk I was using tries to use field10 > 1 and field3 = "FIELD". Now can I include some other conditions and how do they be specifed.

    Note for field10 test I need to do the following:-

    $3=="10";$3=="100" etc as dealing with text but this does not work:-

    Code:
    awk -F, '$10=="10", $10=="100", $3=="FIELD"{print $1"."$2}' data.txt
    awk: syntax error near line 1
    awk: bailing out near line 1
    This works, but I need to modify for different $10 values
    Code:
    awk -F, '$10=="10", $3=="FIELD"{print $1"."$2}' data.txt
    Any suggestions please.

    Andy
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,489
    Rep Power
    1876
    Try something like
    'NF >= 10 && $10 > 1 && $3=="FIELD" { print $1"."$2 }'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    UK
    Posts
    196
    Rep Power
    15
    Thanks salem, this worked a treat.

    Code:
    awk -F, 'NF>10 && $10<1 && $10>10 && $9!=”OFF” && $3=="FIELD" {print $1"."$2}'

IMN logo majestic logo threadwatch logo seochat tools logo