Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2005
    Posts
    41

    Question Unanswered: Filter block of output from a log file

    Hi,

    I've a log file with lot of data in it. like

    Hello how is everyone
    Hope all is well
    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    yahooooo
    gooooooogle 56
    ning 8
    utube
    technorati
    -*-*-*-*-*- RULE EXECUTION -*-*-*-*-*-
    life couldn't be better
    thank you for your response and help

    I need data or block of content appearing as is between the lines "-*-*-*-*-*- OUTPUTS -*-*-*-*-*-" and "-*-*-*-*-*- RULE EXECUTION -*-*-*-*-*-"

  2. #2
    Join Date
    May 2007
    Location
    Milano, Italy
    Posts
    22
    Code:
    awk '$0~/OUTPUTS/,$0~/RULE EXECUTION/{if($0~/OUTPUTS|RULE EXECUTION/)next;else print}' infile

  3. #3
    Join Date
    Mar 2005
    Posts
    41

    AWK question - get a block of output from a file.

    Log file is like this - I am interested in data between first occurrence (from top) of OUTPUT and RULE EXECUTION.

    Answer should be :

    yahooooo
    gooooooogle 56
    ning 8
    utube
    technorati

    Log File

    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    hello
    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    hello
    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    hello
    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    hello
    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    hello


    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-

    yahooooo
    gooooooogle 56
    ning 8
    utube
    technorati



    -*-*-*-*-*- RULE EXECUTION -*-*-*-*-*-

    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    counts
    -*-*-*-*-*- RULE EXECUTION -*-*-*-*-*-

    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    hello
    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    hello

    -*-*-*-*-*- OUTPUTS -*-*-*-*-*-
    counts
    -*-*-*-*-*- RULE EXECUTION -*-*-*-*-*-

  4. #4
    Join Date
    May 2007
    Location
    Milano, Italy
    Posts
    22
    Code:
    awk '{gsub(/.*\*-\n|\n-\*.*/,"",$1);print $1}'  FS="RULE EXECUTION" RS="~" infile
    Use nawk on Solaris.

  5. #5
    Join Date
    Mar 2005
    Posts
    41

    Solution complains about #of input bytes

    awk '{gsub(/.*\*-\n|\n-\*.*/,"",$1);print $1}' FS="RULE EXECUTION" RS="~" infile

    awk: Input line -*-*-*-*-*-*-*-*-*-* cannot be longer than 3,000 bytes.
    The source line number is 1.

  6. #6
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    What about:
    Code:
    awk '$0 ~ /RULE EXECUTION/  {f = 0}              
        f == 1                  {print $0}           
        $0 ~ /OUTPUTS/          {f = 1}' infile
    Regards

  7. #7
    Join Date
    Mar 2005
    Posts
    41

    Only 1st and one instance of the output is needed

    That gives the full log file. I am interested in the data between first occurrence (from top) of OUTPUT and RULE EXECUTION. Thats it, nothing else.

  8. #8
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Must be the awk implementation then. It works perfectly well on my system, using mawk. But let's do something else then; if you only need the lines between the first occurrences of 'OUTPUTS' and the subsequent 'RULE EXECUTION' it's probably faster to use:
    Code:
    sed -e '1,/OUTPUTS/d' -e '/RULE EXECUTION/,$d' infile
    The semantics of these sed expressions are universal.

    Regards

  9. #9
    Join Date
    May 2007
    Location
    Milano, Italy
    Posts
    22
    Quote Originally Posted by gauravjain21
    awk '{gsub(/.*\*-\n|\n-\*.*/,"",$1);print $1}' FS="RULE EXECUTION" RS="~" infile

    awk: Input line -*-*-*-*-*-*-*-*-*-* cannot be longer than 3,000 bytes.
    The source line number is 1.
    I see ...
    Try this:

    Code:
    awk '{rec[NR]=$0}
    /OUTPUTS/{start=NR}
    /RULE EXECUTION/{end=NR;exit}
    END{for(i=start+1;i<end;i++)print rec[i]}' infile

  10. #10
    Join Date
    Mar 2005
    Posts
    41

    This one works - Thanks

    This script rocks - Thanks much.


Posting Permissions

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