Results 1 to 5 of 5

Thread: awk question

  1. #1
    Join Date
    Sep 2003
    Posts
    31

    Unanswered: awk question

    I can match variable $1 and $2 as follow
    awk -F, '{if($1 ~ /'$cust'/ && $2 ~ /'$os'/) print $1, $2, $3}'


    but if I want to do as bellow it is not working
    awk -F, '{if($1=$cust && $2=$os) print $1, $2, $3}'

    I want to use if $1 equal to my customer name
    &&
    $2 equal linux

    what I need to do

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Use quotes like in your first statement (using ~operator) :
    Code:
    awk -F, '{if($1=='$cust' && $2=='$os' ) print $1, $2, $3}'
    Another soltion is to use awk variable (the best solution if the awk script is long) :

    Code:
    awk -F, '{if ($1==CUST && $2==OS) print $1,$2,$3}' CUST=$cust OS=$os
    Jean-Pierre.

  3. #3
    Join Date
    Sep 2003
    Posts
    31
    It did notwork
    I have tried this code by it returns nothing
    awk -F, '{if($1=='$cust' && $2=='$os' ) print $1, $2, $3}'


    The following commands works but I want to know how do I use awk

    cat myfile|grep -e "^$cust,$os"
    awk -F, '{if ($1==mycustomer && $2==linux) print $1,$2,$3}'
    awk -F, '{if($1 ~ /'$cust'/ && $2 ~ /'$os'/) print $1, $2, $3}'

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Sorry, missing double quotes :
    Code:
    awk -F, '{if($1=="'$cust'" && $2=="'$os'" ) print $1, $2, $3}'
    Have you try the second form with awk variables ?
    Jean-Pierre.

  5. #5
    Join Date
    Sep 2003
    Posts
    31
    Yes Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •