DBAsupport.com Forums - Powered by vBulletin
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: awk script question

  1. #1
    Join Date
    Jan 2001
    Posts
    2,828

    Talking

    Hello All

    I am running redhat 6.2 i have the following question
    .i have a text file called st1.txt whose contents are as follows.

    Label Not Found/Identical Yes/No
    -----------------------------------------------------
    Redhat Label |Not found
    Suse Label |Not found
    Suse Report |Not found
    Berhat Label |Not found

    i want to have the count of not found by label.i am using the follwoing awk script but the count si displayed as zero.why is that.

    BEGIN{
    FS="|"
    count=0
    if ( match($2 ,"Label") && $3="Not Found")
    {count=count++}
    print count
    }
    END

    regards
    hrishy









  2. #2
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    because if your field separator is |, $2=Not Found, and $3=nothing ...

  3. #3
    Join Date
    Jan 2001
    Posts
    2,828
    hello Pipo

    To my rescue again .thanks a ton pal ..........

    i ahve modified my code now it contains

    BEGIN{
    FS="|"
    count=0
    if ( match($1,"Label") && $3="Not Found")
    {count=count++}
    print count
    }
    END

    the output is still zero ...

    i have even tried this........

    BEGIN{
    FS="|"
    count=0
    if ( $1 ~ /Label/ && $3 ~ /Not Found/ )
    {count=count+1}
    print count
    }
    END

    the output is still zero .wunderin what could be wrong.

    regards
    hrishy








  4. #4
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    look :

    Some Label | Not found

    $1 = Some Label
    $2 = Not Found
    $3 is NULL

    so try with $2, should be better

  5. #5
    Join Date
    Jan 2001
    Posts
    2,828

    Talking

    hello

    i changed the code as per your instructions .still no luck............grrrrrrrr



    BEGIN{
    FS="|"
    count=0
    if ( $1 ~ /Label/ && $2 ~ /Not Found/ )
    {count=count+1}
    print count
    }
    END

    regards
    hrishy














  6. #6
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    awk -f a.awk datafile

    ------------------ a.awk ------------------
    {
    FS="|"
    if ( $1 ~ /Label/ && $2 ~/Not Found/ ) {
    count += 1
    }
    }
    END {print count}
    -------------------------------------------

  7. #7
    Join Date
    May 2001
    Posts
    55
    BEGIN { FS = "|"
    }
    { if ( ( index ( $1, "Label" ) ) && ( $2 = "Not Found" ) )
    count = count + 1
    }
    END { print count
    }



    This should definitely work.

    count++ was not working in my system.
    count = count + 1 worked !

    A farmer learns more from a bad harvest than a good one

  8. #8
    Join Date
    Jan 2001
    Posts
    2,828

    Talking

    Hello Pipo & Topstar

    well i am still baffled..........its not workin for me.....could one of please check wheather the script works for me.i am greatful to you both for havin worked on my problem.

    regards
    hrishy

  9. #9
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    hmmm, have tested mine, it's working here (Solaris 2.7, ksh) ... what do you get : 0 or nothing ??
    and if you just do {print $1," - ",$2} what do you get ??

  10. #10
    Join Date
    Jan 2001
    Posts
    2,828

    Talking

    well Pipo

    i think i am havin a bad day........i am gettin jelaous of you....
    ;-)...........

    coz i am havin this output if i run {print $1," - ",$2}


    Redhat Label Not found
    Suse Label Not found
    Suse Report Not found
    Berhat Label Not found

    which seems right to me.ahhhhhh my bad luck i guess.

    i broke up with one my best pals today.........guess that explains all the bad luck :-(

    regards
    hrishy


Posting Permissions

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


Click Here to Expand Forum to Full Width