how to get the value of using condition check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lakshmikant
    New Member
    • Jun 2012
    • 3

    how to get the value of using condition check

    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,"interface link.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
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    Is there a reason why you didn't respond to the answer given to you 9hrs ago on devshed?

    Comment

    • lakshmikant
      New Member
      • Jun 2012
      • 3

      #3
      Hi Ron I did not get any answere to repond

      Comment

      • RonB
        Recognized Expert Contributor
        • Jun 2009
        • 589

        #4
        You certainly did get an answer.

        Here is the answer I gave you in that devshed posting.

        The code you posted won't produce the results that you stated from the sample data you posted.

        Based on you sample data, I'd loop over the lines skipping any that don't start with a number, then use the split function to breakup the line into their separate fields. If you use an array slice, you can extract just the 3 needed fields instead of all 7.
        Did you not understand what I was suggesting?

        If my suggestion does not solve your issue, then please provide more details on what you need to accomplish.

        Comment

        Working...