Grep inline use perl

Hi,

i have input like this :

SS-ID VLAN MAC               TIME IP                 RSSI MODE  UAPSD BW GI WMOS DHCP       IDENTITY 
----- ---- ---               ---- --                 ---- ----  ----- -- -- ---- ----       -------- 
1-1   0    C4:46:19:75:C1:55 23m  192.168.5.253      -24  bgn   no    20 S  4.9  ack* 
1-2   0    5C:57:C8:69:8C:1E 3s   192.168.5.254      -38  bg    no    20 L  4.8  ack*

I want the output is "1-1" by grep in line by MAC Address

So far i use this scripts, but doesn't work :

my @macall = qw(print @input); 
    foreach $line (@macall) { 
        if ($line =~ /C4:46:19:75:C1:55:\s+(\S+)/) { 
                $id = $1; 
            } 
        } 
      print "ID = $id"; 
      return (0);

Anybody can help ?

 
$ cat a.txt
SS-ID VLAN MAC               TIME IP                 RSSI MODE  UAPSD BW GI WMOS DHCP       IDENTITY 
----- ---- ---               ---- --                 ---- ----  ----- -- -- ---- ----       -------- 
1-1   0    C4:46:19:75:C1:55 23m  192.168.5.253      -24  bgn   no    20 S  4.9  ack* 
1-2   0    5C:57:C8:69:8C:1E 3s   192.168.5.254      -38  bg    no    20 L  4.8  ack*
 
 
$ perl -lane 'if($_=~/C4:46:19:75:C1:55/){print $F[0];}' a.txt
1-1

what about if i wanna use the perl scripts ?
not use the command?

I believe this is the best way of doing it! Rather writing 10-20 lines of code for this simple task! :slight_smile:

        if($line=~/C4:46:19:75:C1:55/)
        {
                my @F=split(/ /,$line);
                print $F[0];
        }

I thought to write a new program for this. :frowning:

My bad!!