For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > How to grep a particular location value of a line?









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]

 

Author How to grep a particular location value of a line?
Shahriar

2006-10-08, 6:58 pm

Hi,

I have to parse a value from a line of a logfile. The line looks like
this:

maximum 5.91 2.61 881.6 832.4 883.5 211565
211565 211565 99.9 99.8 99.5

Every logfile is same type. I need to compare the value of "5.91" with
a different logfile. The value will be different. My question is how
can I grep the value of "5.91" from that particular format of line and
to compare with the different logfile value(same type of format)?

Any help is appreciated.

Thanks,
Shahriar

Marcel

2006-10-08, 6:58 pm

Hi Shahriar

This might be one possible way on how to do it.

===================
#!/usr/bin/perl -w
use strict;

my $log_line = "maximum 5.91 2.61 881.6 832.4 883.5 211565";
my $number = (split /\s/, $log_line)[1];
print "$number \n";
===================

Hope that helps,
Marcel


Shahriar wrote:
> Hi,
>
> I have to parse a value from a line of a logfile. The line looks like
> this:
>
> maximum 5.91 2.61 881.6 832.4 883.5 211565
> 211565 211565 99.9 99.8 99.5
>
> Every logfile is same type. I need to compare the value of "5.91" with
> a different logfile. The value will be different. My question is how
> can I grep the value of "5.91" from that particular format of line and
> to compare with the different logfile value(same type of format)?
>
> Any help is appreciated.
>
> Thanks,
> Shahriar


Shahriar

2006-10-09, 7:59 am

Hi Marcel,

Unfortuntely it' not grepping the particular number. If you see the
line from the log it has 11 blank spaces before maximum and seven blank
space before the value (5.91) I want to grep.

Can you help with this detail information? Please let me know if you
want to know some more things.

Thanks.

Marcel wrote:[color=darkred]
> Hi Shahriar
>
> This might be one possible way on how to do it.
>
> ===================
> #!/usr/bin/perl -w
> use strict;
>
> my $log_line = "maximum 5.91 2.61 881.6 832.4 883.5 211565";
> my $number = (split /\s/, $log_line)[1];
> print "$number \n";
> ===================
>
> Hope that helps,
> Marcel
>
>
> Shahriar wrote:

FishMonger

2006-10-09, 12:35 pm

Minor adjustment to the regex.

my $number = (split /\s+/, $log_line)[1];
Shahriar

2006-10-12, 6:59 pm

Marcel,

It's working. Thanks for your help.

Regards,
Shahriar
Shahriar wrote:[color=darkred]
> Hi Marcel,
>
> Unfortuntely it' not grepping the particular number. If you see the
> line from the log it has 11 blank spaces before maximum and seven blank
> space before the value (5.91) I want to grep.
>
> Can you help with this detail information? Please let me know if you
> want to know some more things.
>
> Thanks.
>
> Marcel wrote:

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com