加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

我如何像sed一样使用perl?

发布时间:2020-12-14 01:39:08 所属栏目:Linux 来源:网络整理
导读:我有一个文件,有一些条目,如 --ERROR--- Failed to execute the command with employee Name="shayam" Age="34"--Successfully executed the command with employee Name="ram" Age="55"--ERROR--- Failed to execute the command with employee Name="sam"
我有一个文件,有一些条目,如

--ERROR--- Failed to execute the command with employee Name="shayam" Age="34"

--Successfully executed the command with employee Name="ram" Age="55"

--ERROR--- Failed to execute the command with employee Name="sam" Age="23"

--ERROR--- Failed to execute the command with employee Name="yam" Age="3"

我只需要提取命令执行失败的名称和年龄.
在这种情况下,我需要提取shayam 34 sam 23 yam 3.我需要在perl中执行此操作.非常感谢..

解决方法

你的头衔不清楚.无论如何…

while(<>) {
 next if !/^--ERROR/;
 /Name="([^"]+)"s+Age="([^"]+)"/;
 print $1,"  ",$2,"n";
}

可以从stdin读取;当然,您可以将读取循环更改为其他任何内容,并根据您的需要使用某些内容填充哈希或其他内容.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读