I have a file
------------------------------------------------------------------
Port Speed Duplex Flow Ctrl Link Name
---- ----- -------- --TX-----RX-- ------ ------
1 10000 full no no down 1
2 10000 full no no down 2
3 10000 full no no down 3
4 10000 full no no down 4
5 10000 full no no down 5
6 10000 full no no down 6
7 10000 full no no down 7
8 10000 full no no down 8
9 10000 full no no down 9
10 10000 full no no down 10
11 10000 full no no down 11
12 10000 full no no down 12
13 10000 full no no down 13
14 10000 full no no down 14
15 10000 full no no down 15
16 10000 full no no down 16
17 1G/10G full no no down 17
18 1G/10G full no no down 18
19 1000 full no no up 19
20 10000 full no no down 20
and my script is
open FILE,"interfacelink.txt" or die "cannot open file : $!";
my ($line, $ind, $port, $speed, $link);
$ind=$line=~ /Link/;
while (<FILE>) {
$line = $_;
if ( $line =~ /\bLink\b/ ) {
print "port is ", $port, substr($line,1,2). ", ";
print "speed is ", $speed, substr($line,7,5). ", ";
print "link is ", $link, substr($line,42,4)."\n";
}
}
when I run the script I got the output
port is 19, speed is 1000, link is up
need urgent help :I dont know how to check the condition like if the line contain "Link" in the first line then check the port link is up or down and if it is up then get the same out as above