in reply to Re^2: new : greping
in thread new : greping
Final modification to code for extended file syntax
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, '<', 'data.txt' or die "Couldn't open data.txt: $!"; while (! eof inFile) { $line .= ' ' . <inFile>; chomp $line; next if ! ($line =~ /logging\sto\s(device.*?)\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 ();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: new : greping
by pingme8705 (Acolyte) on Sep 08, 2005 at 10:49 UTC | |
by GrandFather (Saint) on Sep 08, 2005 at 11:03 UTC | |
by pingme8705 (Acolyte) on Sep 09, 2005 at 03:00 UTC | |
by GrandFather (Saint) on Sep 09, 2005 at 06:31 UTC | |
by pingme8705 (Acolyte) on Sep 09, 2005 at 08:23 UTC |