Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Perl: Extracting specific text from a .txt file and outputting into a new format

by fisher (Priest)
on Nov 18, 2010 at 10:49 UTC ( #872193=note: print w/replies, xml ) Need Help??


in reply to Perl: Extracting specific text from a .txt file and outputting into a new format

How to find the system name in this log? Please explain using natural language. Does it have static position (say, the very first line)? Does it have empty line before? Maybe, there is some pattern to look for (say, system\d+-.*) ?
  • Comment on Re: Perl: Extracting specific text from a .txt file and outputting into a new format

Replies are listed 'Best First'.
Re^2: Perl: Extracting specific text from a .txt file and outputting into a new format
by fisher (Priest) on Nov 18, 2010 at 11:50 UTC
    well, so what seems to be the problem?
    #!/usr/bin/env perl # use strict; use warnings; open F, "<fff" or die "Aaaahg..."; # current system my $system; # our params here my %box; my %bin; my %bout; my %desc; while (<F>) { /^system\d+-server$/ and do {$system= $_; next}; /^HW a2b.*\(.*\)$/ and $box{$system}= $_; s/^\s*(\d+) packets input.*$/$1/ and $bin{$system}= $_; s/^\s*(\d+) packets output.*$/$1/ and $bout{$system}= $_; s/^Description: (.*)$/$1/ and $desc{$system}= $_; } foreach (keys %desc) { print "System: ". $_; print "Box: ". $box{$_}; print "ByteIn: ". $bin{$_}; print "Byteout: ". $bout{$_}; print "Description: ". $desc{$_}; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://872193]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2017-11-19 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (282 votes). Check out past polls.

    Notices?