Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: new : greping

by wfsp (Abbot)
on Sep 08, 2005 at 12:30 UTC ( #490194=note: print w/ replies, xml ) Need Help??


in reply to new : greping

Hi pingme8705,

Perhaps loading the data into a HoA might help getting hold of the fields a bit easier.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my (%data, $device); while (my $line = <DATA>){ chomp $line; next if $line =~ /^\s*$/; if ($line =~ /logging to ([\w-]+)/){ $device = $1; next; } push @{$data{$device}}, $line; } print Dumper(\%data); __DATA__ logging to device1 is 2.3.5.1 . . . 56% /var 38% / 31% Interleaved device1 Tue Sep 9 11:26:44 ist 2005 logging to device2 is 2.3.5.1 . . . 96% /var 88% / 100% Interleaved device2 Tue Sep 5 10:26:44 GMT 2005 logging to device5-PPP is 2.3.5.1 . . . 156% /var 138% / 131% Interleaved device1 Tue Sep 9 11:26:44 ist 2005 logging to device8-PPm is 2.3.5.1 . . . 596% /var 688% / 100% Interleaved device2 Tue Sep 5 10:26:44 GMT 2005
output
---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" ping.pl $VAR1 = { 'device8-PPm' => [ '596% /var', '688% /', '100% Interleaved', 'device2', 'Tue Sep 5 10:26:44 GMT 2005' ], 'device5-PPP' => [ '156% /var', '138% /', '131% Interleaved', 'device1', 'Tue Sep 9 11:26:44 ist 2005' ], 'device1' => [ '56% /var', '38% /', '31% Interleaved', 'device1', 'Tue Sep 9 11:26:44 ist 2005' ], 'device2' => [ '96% /var', '88% /', '100% Interleaved', 'device2', 'Tue Sep 5 10:26:44 GMT 2005' ] }; > Terminated with exit code 0.


Comment on Re: new : greping
Select or Download Code
Re^2: new : greping
by pingme8705 (Acolyte) on Sep 09, 2005 at 03:15 UTC
    hi wfsp !
    ogging to device1 is 2.3.5.1 . . . 56% /var 38% / 31% Interleaved disks faults avm fre cs us sy id 504956 19880 32 3 24 72 device1 Tue Sep 9 11:26:44 ist 2005 logging to device2 is 2.3.5.1 . . . 96% /var 88% / 100% Interleaved disks faults avm fre cs us sy id 5049 198 32 3 24 72 device2 Tue Sep 5 10:26:44 GMT 2005 logging to device5-PPP is 2.3.5.1 . . . 156% /var 138% / 131% Interleaved disks faults avm fre cs us sy id 956 190 32 3 24 72 device5-PPP Tue Sep 9 11:26:44 ist 2005 logging to device8-PPm is 2.3.5.1 . . . 596% /var 688% / 100% Interleaved device8-PPm disks faults avm fre cs us sy id 56 19880 32 3 24 72 Tue Sep 5 10:26:44 GMT 2005
    this is the content of the logs we get ! and with the help of Grandfather we able to get a sort of partial output. but we need to get the values of avm,fre,id which are in the next line seperated by spaces and also the time stamp thats displayed on the next line in the excel sheet ! this is the code we have now.
    use warnings; use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("data.xls"); my $worksheet = $workbook->add_worksheet(); $worksheet->write ("A1", 'Device'); $worksheet->write ("B1", '/var'); $worksheet->write ("C1", '/'); $worksheet->write ("D1", 'interleaved'); my $row = 2; my $line = ''; my $device; open inFile, '<', 'logs.txt' or die "Couldn't open data.txt: $!"; while (! eof inFile) { $line .= ' ' . <inFile>; chomp $line; next if ! ($line =~ /logging\sto\s(.*?)\s+/i) and ! eof inFile; my $nextDevice = $1; if ($line =~ /(\d+)%\s+\/var\s+(\d+).*?(\d+)%\s+Interleaved\s+(\w+)/ +i) { $worksheet->write("A$row", "$device"); $worksheet->write("B$row", "$1"); $worksheet->write("C$row", "$2"); $worksheet->write("D$row", "$3"); ++$row; print "$device $1, $2, $3\n"; } $device = $nextDevice; $line = ''; } close inFile; $workbook->close ();
    i am making modifaication in the $line to grep the need. <code>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://490194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-12-25 01:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls