Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Need help to parse the text

by bibo (Pilgrim)
on Jun 17, 2004 at 04:31 UTC ( #367530=note: print w/replies, xml ) Need Help??


in reply to Need help to parse the text

Hey GS, try this. It's not fancy, but it does the job...
#!/usr/bin/perl use strict; my $filename = "ifconfig.txt"; # my @junk; open(JUNK, $filename)|| die "Cannot open file $filename!"; @junk = <JUNK>; close(JUNK); my ($interface, $istatus, $item); foreach $item (@junk) { chop $item; $interface = $item if ($item =~ m/^[A-z][A-z][0-9]:/); $istatus=""; if ($item =~ m/status:/) { my @sjunk = split (/ /, $item); $istatus = $sjunk[$#sjunk]; $istatus = $sjunk[$#sjunk-1] . " " . $sjunk[$#sjunk] if ($istatus + ne "active"); } print "$interface $istatus\n" if ($istatus ne ""); }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2022-05-24 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?