Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Need help to parse the text

by davidj (Priest)
on Jun 17, 2004 at 05:20 UTC ( #367534=note: print w/replies, xml ) Need Help??


in reply to Need help to parse the text

I assume that the format of the ifconfig -a output will always be the same; that is, interface followed by interface information. If that is the case, then the following code sample will work for you. NOTE:
1) the output of ifconfig -a has been stored in a file
2) the interface information is stored in a hash where the interface name is the key and its status is the value.

#!/usr/bin/perl use strict; my ($if, %hash, $key); open(FILE, "<f.txt"); while(<FILE>) { chomp $_; ($if = $_) =~ s/^(\w+?):.+/$1/ if $_ =~ m/^\w+:/; ($hash{$if} = $_) =~ s/.+status:\s+(.+)/$1/ if $_ =~ m/status/; } close(FILE); foreach $key (keys %hash) { print "$key: $hash{$key}\n"; } exit;
hope this helps,
davidj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2022-08-18 01:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?