E err:1242 01/12/2009 connectivity error
the database connection failed.
number of field entries allocated 20, used 1
DBName=Oracle10g ErrorNumber=10
E err:1892 01/12/2009 connectivity error
the database connection failed.
number of field entries allocated 20, used 2
DBName=Oracle10g ErrorNumber=32
Here 'E' refers Error.
i want a perl script that displays only the first error message.. that is the first part of error message (lines till next E).
sample output..
E err:1242 01/12/2009 connectivity error
the database connection failed.
number of field entries allocated 20, used 1
DBName=Oracle10g ErrorNumber=10
I tried like this
foreach $lines (@raw_data){
if($lines=~m/^E /){
print "$lines";
}
}
This perl script displaying only the first line
E err:1242 01/12/2009 connectivity error
and the remaining lines are not displayed.
Can u suggest a solution for this..
$
$ cat -n f9
1 E err:1242 01/12/2009 connectivity error
2 the database connection failed.
3 number of field entries allocated 20, used 1
4 DBName=Oracle10g ErrorNumber=10
5 E err:1892 01/12/2009 connectivity error
6 the database connection failed.
7 number of field entries allocated 20, used 2
8 DBName=Oracle10g ErrorNumber=32
$
$ perl -lne 'if (/^E/ && !defined $x){$x=1} elsif (/^E/ && $x==1){$x=0} print if $x==1' f9
E err:1242 01/12/2009 connectivity error
the database connection failed.
number of field entries allocated 20, used 1
DBName=Oracle10g ErrorNumber=10
$
$
If you understood the Perl one-liner completely, then it shouldn't be difficult for you to tweak it so as to display the second part of the error.
I shall leave that as an exercise for you.
otherwise, choose some CPAN module which support regexp $/;
local $/;
my $str=<DATA>;
my @tmp = split(/(?<=\n)(?=E)/,$str);
print $tmp[0];
__DATA__
E err:1242 01/12/2009 connectivity error
the database connection failed.
number of field entries allocated 20, used 1
DBName=Oracle10g ErrorNumber=10
E err:1892 01/12/2009 connectivity error
the database connection failed.
number of field entries allocated 20, used 2
DBName=Oracle10g ErrorNumber=32