in reply to Re^4: new : greping
in thread new : greping

As you will have seen the lines in each record are concatenated together to form one long line then the regex /(\d+)%\s+\/var\s+(\d+).*?(\d+)%\s+Interleaved\s+(\w+)/ is used to pull out the data of interest. You simply need to add more capture fields to gather the extra data and then to print that in the print "$device $1, $2, $3\n"; line and in extra $worksheet->write("D$row", "$3"); lines.

See perlretut, perlre and perlreref for regular expression information.


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^6: new : greping
by pingme8705 (Acolyte) on Sep 09, 2005 at 03:00 UTC
    hello father ! i have tried with the following line:   ($line =~ /(\d+)%\s+\/var\s+(\d+).*?(\d+)%\s+Interleaved\s+.*?avm\s+fre\s+(\d+)\s+(+\d)+\s+(\w+)/i) i have also added the print lines as said by you !
    $worksheet->write("E$row", "$4"); print "$device $1, $2, $3, $4\n";
    but still no go !

      You should reread the regex documentation. Take particular note of what \d matches and what \w matches. I think then you will see the problem for yourself.


      Perl is Huffman encoded by design.
        hi father !
        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'); $worksheet->write ("E1", 'avm'); $worksheet->write ("F1", 'fre'); $worksheet->write ("G1", 'cs'); $worksheet->write ("H1", 'us'); $worksheet->write ("I1", 'sy'); $worksheet->write ("J1", 'id'); $worksheet->write ("K1", 'Date'); 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+.* +?avm\s+.*?fre\s+.*?cs\s+.*?us\s+.*?sy\s+.*?id\s+.*?(\d+)\s+(\d+)\s+(\ +d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\w+)/i) ($line =~ /(\d+)%\s+\/var\s+(\d+).*?(\d+)%\s+Interleaved\s+.*?avm +\s+.*?fre\s+.*?cs\s+.*?us\s+.*?sy\s+.*?id\s+.*?GMT\s+(\d\d:\d\d:\d\d) +\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\w+)/i) #($line =~ /(\d+)%\s+\/var\s+(\d+).*?(\d+)%\s+Interleaved\s+.*?avm +\s+.*?fre\s+.*?id\s+.*?\s+(\d+)\s+(\d+)\s+(\w+)/i) #($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"); $worksheet->write("E$row", "$4"); $worksheet->write("F$row", "$5"); $worksheet->write("G$row", "$6"); $worksheet->write("H$row", "$7"); $worksheet->write("I$row", "$8"); $worksheet->write("j$row", "$9"); $worksheet->write("j$row", "$10"); ++$row; print "$device $1, $2, $3, $4, $5, $6, $7, $8, $9, $10\n"; } $device = $nextDevice; $line = ''; } close inFile; $workbook->close ();
        is my final code and i couldn't get the date stamp. that's the only problem !