Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正在分析cmdshell中的fcinfo输出_Regex_Linux_Perl_Shell - Fatal编程技术网

Regex 正在分析cmdshell中的fcinfo输出

Regex 正在分析cmdshell中的fcinfo输出,regex,linux,perl,shell,Regex,Linux,Perl,Shell,我有下面的输出,我正试图像这样解析它 PS C:\Users\Administrator> fcinfo /details adapter: com.microsoft-Virtual Fibre Channel HBA-0 node_wwn: c0:03:ff:00:00:ff:ff:00 fabric: 00:00:00:00:00:00:00:00 port_wwn: c0:03:ff:58:b6:20:00:02 osdevice: \\.\Scsi1:

我有下面的输出,我正试图像这样解析它

PS C:\Users\Administrator> fcinfo /details

  adapter: com.microsoft-Virtual Fibre Channel HBA-0
 node_wwn: c0:03:ff:00:00:ff:ff:00
   fabric: 00:00:00:00:00:00:00:00
 port_wwn: c0:03:ff:58:b6:20:00:02
 osdevice: \\.\Scsi1:
    venid: x0
   prodid: x0
但是我发现使用下面的代码并不是一个干净的解析

my $listHBAs = `fcinfo /details`;
my @lines = split(/\n/,$listHBAs);
my $wwns;
foreach (@lines) {
     if($_ =~ /port_wwn \s+ : (.*)$/){
         &runSsh($arrayIP, "$ig --wwpn $1");
     }
}

您的regexp与您提供的输出不匹配,并且由于不必要的预处理(即
split
)而使事情变得有些复杂


如果只使用一个
端口_wwn
If
while

一样好,那么当命令在Windows上运行时,为什么要将它标记为Linux?您看起来好像在为正则表达式使用扩展格式,但没有在正则表达式的末尾添加
/x
。您还需要一个带有
\s+
的空间,但示例输出显示没有空间:
m/port\u wwn\s*:\s*(.*)$/x
my $listHBAs = `fcinfo /details`;
while ($listHBAs =~ /port_wwn\s*:\s*(\S*)$/gm) {
    &runSsh($arrayIP, "$ig --wwpn $1");
}