Home > Archive > PERL Beginners > November 2007 > Formating the log
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Avinashsuratkal 2007-11-21, 10:01 pm |
| Hi,
I have the following log and my requirement is to capture the block
from one "-->" symbol to another. and put it in other file, using
perl.
---------------------------------
--> Checking Server Hostname <--
---------------------------------
Server Hostname: xxxxxxxxx
---------------------------------------
--> Checking Authentication Domain <--
---------------------------------------
Server is authenticating against: xxxxxxxxx
--------------------------------------
--> Validating DNS Server Entries <--
--------------------------------------
Servers should conform to global ANYCast Standard
Thanks
Avinash
| |
| Yitzle 2007-11-21, 10:01 pm |
| On Nov 21, 2007 11:28 AM, avinashsuratkal <avinash.suratkal@gmail.com> wrote:
> Hi,
>
> I have the following log and my requirement is to capture the block
> from one "-->" symbol to another. and put it in other file, using
> perl.
>
> ---------------------------------
> --> Checking Server Hostname <--
> ---------------------------------
> Server Hostname: xxxxxxxxx
> ---------------------------------------
> --> Checking Authentication Domain <--
> ---------------------------------------
> Server is authenticating against: xxxxxxxxx
>
> --------------------------------------
> --> Validating DNS Server Entries <--
> --------------------------------------
> Servers should conform to global ANYCast Standard
>
> Thanks
> Avinash
You mean you want to turn the above input into somthing like this?
-------------------------------------
Checking Server Hostname
Checking Authentication Domain
Validating DNS Server Entries
-------------------------------------
$ perl -e 'while(<> ){print "$1\n" if /-->(.*)<--/; }' inputFile > outputFile
| |
| Avinashsuratkal 2007-11-22, 7:59 am |
| On Nov 22, 2:27 am, yit...@users.sourceforge.net (Yitzle) wrote:
> On Nov 21, 2007 11:28 AM, avinashsuratkal <avinash.surat...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
> You mean you want to turn the above input into somthing like this?
> -------------------------------------
> Checking Server Hostname
> Checking Authentication Domain
> Validating DNS Server Entries
> -------------------------------------
>
> $ perl -e 'while(<> ){print "$1\n" if /-->(.*)<--/; }' inputFile > outputFile- Hide quoted text -
>
> - Show quoted text -
Hi Yitzle,
Thank you for the reply...
I want my output to be entered temporary in /tmp/output for further
processing.
--> Checking Server Hostname <--
---------------------------------
Server Hostname: xxxxxxxxx
Thanks.
| |
| Avinashsuratkal 2007-11-22, 7:00 pm |
| On Nov 22, 2:22 pm, avinash.surat...@gmail.com (Avinashsuratkal)
wrote:
> On Nov 22, 2:27 am, yit...@users.sourceforge.net (Yitzle) wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Hi Yitzle,
>
> Thank you for the reply...
>
> I want my output to be entered temporary in /tmp/output for further
> processing.
>
> --> Checking Server Hostname <--
> ---------------------------------
> Server Hostname: xxxxxxxxx
>
> Thanks.- Hide quoted text -
>
> - Show quoted text -
Hi,
In short I need to read the text between 2 lines, which can be
incorporated in the perl script, but not a one-liner.
Thanks,
| |
| Rob Coops 2007-11-22, 7:00 pm |
| It could be just me but.....
perl -e 'while(<> ){print "$1\n" if /-->(.*)<--/; }' inputFile > outputFile
is pretty much the same as somethign like:
#!/usr/bin/perl
use strict;
use warnings;
my @array;
open( IN, "<inFile.log") or die $!;
while (<IN> ) {
my ($text) = $_ =~ m/-->(.*)<--/;
push( @aaray, $text);
}
close(IN);
foreach( @array ) { print $_ . "\n"; }
Then again if you are modifying an existing script and are not able to see
that the one liner and the "script" code is basicaly the same you might want
to read up a bit on perl and how things work before you start modifying an
existing script.
Regards,
Rob
On Nov 22, 2007 3:57 PM, avinashsuratkal <avinash.suratkal@gmail.com> wrote:
> On Nov 22, 2:22 pm, avinash.surat...@gmail.com (Avinashsuratkal)
> wrote:
> wrote:
> outputFile- Hide quoted text -
>
> Hi,
>
> In short I need to read the text between 2 lines, which can be
> incorporated in the perl script, but not a one-liner.
>
> Thanks,
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
| |
| Rob Dixon 2007-11-22, 7:00 pm |
| avinashsuratkal wrote:
>
> In short I need to read the text between 2 lines, which can be
> incorporated in the perl script, but not a one-liner.
I'm afraid it's very unclear what it is you need. Can you give a
real-world example of your input and required output please?
Rob
| |
| Ron Bergin 2007-11-22, 7:00 pm |
| On Nov 22, 6:57 am, avinash.surat...@gmail.com (Avinashsuratkal)
wrote:
> On Nov 22, 2:22 pm, avinash.surat...@gmail.com (Avinashsuratkal)
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Hi,
>
> In short I need to read the text between 2 lines, which can be
> incorporated in the perl script, but not a one-liner.
>
> Thanks,
You're not very clear in your question, but my understanding is that
you want the line of text following /-->(.*)<--/
#!/usr/bin/perl
use strict;
use warnings;
my $last_line;
while(my $current_line = <DATA> ) {
if ($last_line && $last_line =~ /^-+$/) {
print $current_line unless $current_line =~ /-->.+<--/;
}
$last_line = $current_line;
}
__DATA__
---------------------------------
--> Checking Server Hostname <--
---------------------------------
Server Hostname: xxxxxxxxx
---------------------------------------
--> Checking Authentication Domain <--
---------------------------------------
Server is authenticating against: xxxxxxxxx
--------------------------------------
--> Validating DNS Server Entries <--
--------------------------------------
Servers should conform to global ANYCast Standard
| |
| Ron Bergin 2007-11-22, 7:00 pm |
| On Nov 22, 6:57 am, avinash.surat...@gmail.com (Avinashsuratkal)
wrote:
>
> In short I need to read the text between 2 lines, which can be
> incorporated in the perl script, but not a one-liner.
>
> Thanks,
If my interpretation of your needs is correct, then this will do the
job.
#!/usr/bin/perl
use strict;
use warnings;
while(my $current_line = <DATA> ) {
print "$1\n" if $current_line =~ /^\s+(Servers? .+)/;
}
__DATA__
---------------------------------
--> Checking Server Hostname <--
---------------------------------
Server Hostname: xxxxxxxxx
---------------------------------------
--> Checking Authentication Domain <--
---------------------------------------
Server is authenticating against: xxxxxxxxx
--------------------------------------
--> Validating DNS Server Entries <--
--------------------------------------
Servers should conform to global ANYCast Standard
| |
| Avinashsuratkal 2007-11-22, 7:00 pm |
| On Nov 22, 10:47 pm, rob.di...@350.com (Rob Dixon) wrote:
> avinashsuratkal wrote:
>
>
>
>
>
>
>
>
>
>
>
> I'm afraid it's very unclear what it is you need. Can you give a
> real-world example of your input and required output please?
>
> Rob- Hide quoted text -
>
> - Show quoted text -
Hi,
Sorry for that...
Following is the real world example.
Input File.
---------------------------------
--> Checking Server Hostname <--
---------------------------------
Server Hostname: xxxxxxxxx
---------------------------------------
--> Checking Authentication Domain <--
---------------------------------------
Server is authenticating against: xxxxxxxxx
--------------------------------------
--> Validating DNS Server Entries <--
--------------------------------------
Servers should conform to global ANYCast Standard
DNS Name : xxxxxx [WARNING]
Please check the DNS name.
--------------------------------------
--> Validating APP Server Entries <--
--------------------------------------
Buffer size: [WARNING]
Invalid Log count. Required buffer size is 20.
Output File
Validating DNS Server Entries
--------------------------------------
DNS Name : xxxxxx [WARNING]
Please check the DNS name.
Validating APP Server Entries
--------------------------------------
Buffer size: [WARNING]
Invalid Log count. Required buffer size is 20.
Here we are capturing only the WARNING messages along with the
Heading.
Thanks.
| |
| Avinashsuratkal 2007-11-22, 7:00 pm |
| On Nov 22, 7:57 pm, avinash.surat...@gmail.com (Avinashsuratkal)
wrote:
> On Nov 22, 2:22 pm, avinash.surat...@gmail.com (Avinashsuratkal)
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Hi,
>
> In short I need to read the text between 2 lines, which can be
> incorporated in the perl script, but not a one-liner.
>
> Thanks,- Hide quoted text -
>
> - Show quoted text -
Hi,
I figured out the below code and it worked.
my $file = '/tmp/log.txt';
open FILE, $file or die $!;
while (<FILE> )
{
print if /PATERN1/ .. /PATERN2/;
}
close FILE;
But now I want to put the output of "print if /PATERN1/ .. /PATERN2/;"
into a file.
|
|
|
|
|