a better way to grep until end of error message, although most seem to be 1 or 2 line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting a better way to grep until end of error message, although most seem to be 1 or 2 line
# 8  
Old 05-08-2009
well.... any ideas on how this is done?
# 9  
Old 05-08-2009
show more samples of your error file.
# 10  
Old 05-09-2009
Quote:
Originally Posted by VGR
The output i was looking for :


SQL0204N occoured 3 times
[description] SQL0204N "ITUAM.VW_TT_VALUES" is an undefined name.
SQLSTATE=42704
blah blah blah....

SQL3196N occoured 7 times
[description] SQL3196N The input file was not found
blah blah...
......
.... [The no. of lines varies for this error description]
..
blah blah blah....


how do i get the entire description part?
The only cue is that there is a blank line after the description is over in the output.log file which i am reading.
Here's one way to do it:

Code:
$ 
$ cat input.txt
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:   

SQL0204N "ITUAM.VW_TT_VALUES" is an undefined name. 
SQLSTATE=42704                                      
blah blah blah....                                  

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:   

SQL0204N "ITUAM.VW_TT_VALUES" is an undefined name. 
SQLSTATE=42704                                      
blah blah blah....                                  

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:

SQL3196N The input file was not found
blah blah...
......
.... [The no. of lines varies for this error description]
..
blah blah blah....

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned: success
$
$
$ perl -ne 'BEGIN {$/=""} while (/((SQL\d{4}[A-Z]).*)/sg) {$count{$2.":".$1}++}
> END {foreach $key (keys %count){
>        $x = (split(/:/, $key))[0];
>        print "$x occurred $count{$key} times\n[description] $key";
>      }}' input.txt
SQL3196N occurred 1 times
[description] SQL3196N:SQL3196N The input file was not found
blah blah...
......
.... [The no. of lines varies for this error description]
..
blah blah blah....

SQL0204N occurred 2 times
[description] SQL0204N:SQL0204N "ITUAM.VW_TT_VALUES" is an undefined name.
SQLSTATE=42704
blah blah blah....

$
$

HTH,
tyler_durden

____________________________________________________________
"This is your life and it's ending one minute at a time."
# 11  
Old 05-09-2009
Just a more readable script for you ...

Code:
use strict;
use Data::Dumper;

open (FILE, 'input.txt') or die "input.txt : $!\n";
my @wanted = ();
my $in_section = 0;          # this is a flag that indicates start of 'data-store'
                                        # '0' indicates 'do not-store-data'
                                        # '1' indicates 'store-data'
my $line = '';
while (<FILE>) {
    chomp;
    if (/^\s*SQL\d{4}[A-Z].*/i) {           # start 'data-store'
        $line .= "$_\n";
        $in_section = 1;                      # set our flag to one
        next;
    }
    if (/^\s*$/ and $in_section) {         # end the 'data-store'
        $in_section = 0;                     # unset our flag
        push @wanted, $line;
        $line = '';
    }
    $line .= "$_\n" if ($in_section);
}
close FILE;
print Dumper(\@wanted);

You may change the regexp patterns to have different start 'data-store' & end 'data-store' criterion
___________
My Perl blog
# 12  
Old 05-09-2009
Try this:

Code:
awk '$0 ~ /^SQL/{
p=$1;
while ($0 !~ /^ *$/)
{
s=(n=0)? $0:s"\n"$0
getline
};c[p]++;a[p]=s;n=0;s="";next
}END{for(p in a)printf("%s%s%d%s%s%s\n\n",p," occured ",c[p]," times\n","[description] ",a[p])}' input.txt


cheers,
Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep after - til the end of the line

Hi, i need to cat a file after # till the end of the file usually ill do cat /etc/somthing | grep -A999999 # but its not that professional thanks edit by bakunin: please use CODE-tags (or ICODE-tags) for code and data. Thank you. (9 Replies)
Discussion started by: batchenr
9 Replies

2. SCO

Grep to ignore suffix & find end of line

In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
Discussion started by: wbport
7 Replies

3. Shell Programming and Scripting

Grep start and end line of each segments in a file

Cat file1 -------- ---------- SCHEMA.TABLE1 insert------- update----- ------------- ---------- SCHEMA.TABLE2 insert------- update----- ----------- ------------ SCHEMA.TABLE3 insert------- update----- ------------ grep -n SCHEMA > header_file2.txt (2 Replies)
Discussion started by: Veera_V
2 Replies

4. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

5. Homework & Coursework Questions

end of line error

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: #/bin/sh -xv #Author: Lauren Buecker #Date: September 28 2012 #Class COP3353 #Assignment: Assignment 4... (7 Replies)
Discussion started by: swimmerbhs
7 Replies

6. Shell Programming and Scripting

AWK-grep from line number to the end of file

Does anyone know how to use awk to act like grep from a particular line number to the end of file? I am using Solaris 10 and I don't have any GNU products installed. Say I want to print all occurrences of red starting at line 3 to the end of file. EXAMPLE FILE: red green red red... (1 Reply)
Discussion started by: thibodc
1 Replies

7. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

8. UNIX for Advanced & Expert Users

Is there a better way to grep until end of error message?

My file creates an output log after which includes a few sql queries. I segregate them into warnings and errors and then get a total count. The errors' and warnings' lines always start with SQL{4} followed by the details of the error. This is what im doing as o now... errors=`grep -A 1 -E... (1 Reply)
Discussion started by: VGR
1 Replies

9. Solaris

syntax error at line 59: `end of file' unexpected

Hello... I'm trying to run the sshd script, but I keep geting the Syntax errot message . Here's the last few lines on the script. set nu in vi shows 58 lines, but I keep getting error referring to line 59. Any help is appreciated. Thanks, Remi else echo... (4 Replies)
Discussion started by: Remi
4 Replies

10. UNIX for Dummies Questions & Answers

grep error message

hi, I get this error message after I pipe a lot of output into grep. Does anyone know what his means? grep: writing output: Invalid argument thanks, gammaman (3 Replies)
Discussion started by: gammaman
3 Replies
Login or Register to Ask a Question