in reply to Remove text after and before
You could replace your source data with this:
my @NIC = split("\n", `ip link | sed -n 1~2p | cut -d':' -f2 | tr -d ' '`);
and go from there, though that's not really the Perl way :P
A more perlish way would be like this:
my @NIC = split("\n", `ip link | sed -n 1~2p | cut -d':' -f2 | tr -d ' '`);
and go from there, though that's not really the Perl way :P
A more perlish way would be like this:
(For some reason map { s/^[0-9]+:\ ([a-z]+[0-9]*):\ .*$/$1/; } grep ... doesn't seem to work).my @raw_data = `ip link`; my @NIC = grep { /^\d+:\ /; } @raw_data; for (@NIC) { chomp; s/^[0-9]+:\ ([a-z]+[0-9]*):\ .*$/$1/; } Data::Dump::dd(@NIC);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Remove text after and before
by moritz (Cardinal) on May 22, 2012 at 10:07 UTC |
In Section
Seekers of Perl Wisdom