我如何像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" 我只需要提取命令执行失败的名称和年龄. 解决方法
你的头衔不清楚.无论如何…
while(<>) { next if !/^--ERROR/; /Name="([^"]+)"s+Age="([^"]+)"/; print $1," ",$2,"n"; } 可以从stdin读取;当然,您可以将读取循环更改为其他任何内容,并根据您的需要使用某些内容填充哈希或其他内容. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |