我正在尝试匹配以char'*'开头的行。文件mac-address.txt如下:
Legend: * - primary entry
age - seconds since last seen
n/a - not available
vlan mac address type learn age ports
------+----------------+--------+-----+----------+--------------------------
* 14 782b.cb87.b085 dynamic Yes 0 Gi4/39
* 400 c0ea.e459.913d dynamic Yes 0 Gi6/21
* 400 0017.c59a.23aa dynamic Yes 0 Gi3/37
* 400 d4be.d96a.050f dynamic Yes 0 Gi1/12
我有这样的工作。
#!/usr/bin/perl
use strict;
use warnings;
my $line;
open FH, '<', "mac-address.txt";
while ($line = <FH>)
{
if ($line =~ m/^\S/){
print ("$line");
}
}
close FH;
但它与一些不需要的行一起工作如下:
Legend: * - primary entry
------+----------------+--------+-----+----------+--------------------------
* 14 782b.cb87.b085 dynamic Yes 0 Gi4/39
* 400 c0ea.e459.913d dynamic Yes 0 Gi6/21
* 400 0017.c59a.23aa dynamic Yes 0 Gi3/37
* 400 d4be.d96a.050f dynamic Yes 0 Gi1/12
请您能以一些适当的方式帮助我,只保留包含*的行,并消除其他行。如果出现问题,请通知我。谢谢。