in reply to
grep in line and print
Hello justbow, and welcome to the Monastery!
Perhaps this is what you’re looking for:
#! perl
use strict;
use warnings;
while (my $line = <DATA>)
{
if ($line =~ /C4:46:19:75:C1:55/)
{
print "ID = ", (split /\s+/, $line)[0], "\n";
}
}
__DATA__
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*
Output:
12:28 >perl 495_SoPW.pl
ID = 1-1
12:28 >
Update: The following is probably clearer:
#! perl
use strict;
use warnings;
while (my $line = <DATA>)
{
chomp $line;
my @recs = split /\s+/, $line;
if ($recs[2] eq 'C4:46:19:75:C1:55')
{
print "ID = ", $recs[0], "\n";
}
}
__DATA__
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*
(Same output.)
See split.
Hope that helps,