I would start with:
$ echo "--INFO----- Command processing: Name='shayam' Age='19' Project='Alwa'
--ERROR---- Failed to process
--INFO----- Command processing: Name='ram' Age='23' Project='Alwa'
--INFO----- Command processing: Name='raja' Age='24' Project='Alwa'
--INFO----- Command processing: Name='shyla' Age='27' Project='Alwa'
--ERROR---- Failed to process " | perl -ne '
if (/^--INFO--/) {@line = split;}
if (/^--ERROR--/) {print "$line[3] $line[4]\n";}'
which produces:
Name='shayam' Age='19'
Name='shyla' Age='27'
All it does is store the information from every INFO
line and then print it out when you get an ERROR
line.
You'll notice it still has the quotes around the values but, if you really want to get rid of those, use the (very simplistic) proc.pl
script:
#!/bin/perl -w
while (<STDIN>) {
if (/^--INFO--/) {
@line = split;
}
if (/^--ERROR--/) {
$l3 = $line[3];
$l4 = $line[4];
$l3 =~ s/'//g;
$l4 =~ s/'//g;
print "$l3 $l4\n";
}
}
Running this with:
$ echo "--INFO----- Command processing: Name='shayam' Age='19' Project='Alwa'
--ERROR---- Failed to process
--INFO----- Command processing: Name='ram' Age='23' Project='Alwa'
--INFO----- Command processing: Name='raja' Age='24' Project='Alwa'
--INFO----- Command processing: Name='shyla' Age='27' Project='Alwa'
--ERROR---- Failed to process " | ./proc.pl
gives:
Name=shayam Age=19
Name=shyla Age=27
You can use any input file or stream with that (for example):
cat file.txt | ./proc.pl
or:
./proc.pl <file.txt