If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Filter block of output from a log file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-25-07, 16:34
gauravjain21 gauravjain21 is offline
Registered User
 
Join Date: Mar 2005
Posts: 41
Question 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 -*-*-*-*-*-"
Reply With Quote
  #2 (permalink)  
Old 06-25-07, 17:29
radoulov radoulov is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 06-25-07, 22:56
gauravjain21 gauravjain21 is offline
Registered User
 
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 -*-*-*-*-*-
Reply With Quote
  #4 (permalink)  
Old 06-26-07, 06:46
radoulov radoulov is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 06-26-07, 14:34
gauravjain21 gauravjain21 is offline
Registered User
 
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.
Reply With Quote
  #6 (permalink)  
Old 06-26-07, 15:04
Tyveleyn Tyveleyn is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 06-26-07, 16:23
gauravjain21 gauravjain21 is offline
Registered User
 
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.
Reply With Quote
  #8 (permalink)  
Old 06-26-07, 18:17
Tyveleyn Tyveleyn is offline
Registered User
 
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
Reply With Quote
  #9 (permalink)  
Old 06-27-07, 01:27
radoulov radoulov is offline
Registered User
 
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
Reply With Quote
  #10 (permalink)  
Old 06-27-07, 22:43
gauravjain21 gauravjain21 is offline
Registered User
 
Join Date: Mar 2005
Posts: 41
This one works - Thanks

This script rocks - Thanks much.

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On