编程:perl 中,怎样将文本全部读取出
ok,201807261150400:DeviceID:19DeviceRevision:2FirmwareRevision:2.20Version:2.0Manufac...
ok,20180726115040 0:Device ID : 19
Device Revision : 2
Firmware Revision : 2.20
Version : 2.0
Manufacturer ID : 11
Manufacturer : Hewlett-Packard
Product ID : 8192 (0x2000)
Product Name : Unknown (0x2000)
Device Available : yes
Provides Device SDRs : no
Additional Device Support :
Sensor Device
SDR Repository Device
SEL Device
FRU Inventory Device
Chassis Device
OsName : VMware ESXi 6.0.0 build-5050593.0 build-505059
Model : ProLiant DL388 Gen9
以上文本我想全部显示出 ,用$0只显示第一行,$1显示第一个字符ok,$2显示后面的,第一行以下怎么弄 展开
Device Revision : 2
Firmware Revision : 2.20
Version : 2.0
Manufacturer ID : 11
Manufacturer : Hewlett-Packard
Product ID : 8192 (0x2000)
Product Name : Unknown (0x2000)
Device Available : yes
Provides Device SDRs : no
Additional Device Support :
Sensor Device
SDR Repository Device
SEL Device
FRU Inventory Device
Chassis Device
OsName : VMware ESXi 6.0.0 build-5050593.0 build-505059
Model : ProLiant DL388 Gen9
以上文本我想全部显示出 ,用$0只显示第一行,$1显示第一个字符ok,$2显示后面的,第一行以下怎么弄 展开
1个回答
展开全部
my $str;
do {local $/=undef; $str = <DATA>;};
if ($str =~ /((\w+).*?)\n(.*)/ms) {
print "\$1 = $1\n";
print "\$2 = $2\n";
print "\$3 = $3\n";
}
__DATA__
ok,20180726115040 0:Device ID : 19
Device Revision : 2
Firmware Revision : 2.20
Version : 2.0
Manufacturer ID : 11
Manufacturer : Hewlett-Packard
Product ID : 8192 (0x2000)
Product Name : Unknown (0x2000)
Device Available : yes
追问
type=Single
ptype=regexp
pattern=(ok|unknown),(.*)
desc=bmcResSticConfigsstate
action=eval %a (\
if ( "$1" eq "ok" ) {\
cce_set_all("ResSticConfigs",OK,"0","正常","$2","");\
}\
这个不知道你了解不,第一行的提出来了,后面的就没了尴尬////
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询