Hi Chaps

Need some help with this, I’m attempting to try and read in the below which is system output for one of the NIC on my server.

2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:4e:97:a1 brd ff:ff:ff:ff:ff:ff

I want to be able to strip away all characters before eth1 including all white space and eveything after eth1: so I’m just left with eth1.

I have tried various regular expression but can’t seem to trap : unless you can think of a better way to do it.

Then print out back to the file handle just the NIC adapter name

This is what I have so far, not much to go on but should give oyu an idea of what im trying to do

#!/usr/bin/perl -w my $nicount = `ip link >/tmp/nic.txt`; open(NICFH, "/tmp/nic.txt") || die "can't open file: $!"; my @NIC = <NICFH>; foreach my $file (@NIC) { $file =~ s/\d\:\s//; print $file; }

In reply to Remove text after and before by muizelaar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.