Thread: 2 if statement

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

    Join Date
    Mar 2006
    Posts
    71
    Rep Power
    12

    2 if statement


    I have a file for eg abc.xyz with the following info

    7411 2.3
    7403 1.1
    7404 1.1
    7405 1.2
    7406 1.2
    7407 1.2
    7411 1.5
    7410 1.6
    7411 1.5
    7410 4
    7411 2.3
    7410 2.6
    7410 9.4
    7411 2
    7410 2.3
    7410 8.5
    7412 112.1
    7410 20.9
    7411 20.5
    7411 1.1
    7410 1.5
    7411 1.4
    7410 1.3
    7411 1.1
    7411 1.1
    7411 1.1
    7410 1.4
    7411 1.1
    7410 1.5

    I want to print $1 if $1=7411 and $2 > 1.0
    and also print $1 if $1=7410 and $2 > 1.3

    My output should contain only 7411 and 7410 with $2 conditions defined
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Posts
    47
    Rep Power
    23
    Code:
    awk ' ( $1 == 7410 && $2 > 1 ) || ( $1 == 7411 && $2 > 1.3 ) ' file
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    71
    Rep Power
    12
    Thanks friend for the quick reply
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    71
    Rep Power
    12

    Small help required again


    What would be the syntax if
    I want to print $1 if $1=7401 to 7412 and $2 > 1.0
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Posts
    47
    Rep Power
    23
    Code:
    awk ' ( $1 >= 7401 || $1 <= 7412 ) && $2 > 1 { print $1 } ' file
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    71
    Rep Power
    12
    thanks once again

IMN logo majestic logo threadwatch logo seochat tools logo