sed删除多行 [英] sed delete multiple lines

查看:244
本文介绍了sed删除多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用sed删除多行几乎没有问题.我阅读了很多指南和讨论,但都没有帮助.我有一个xml文件,我需要删除以下三行中的更多内容:

I have little problem with deleting multiple lines with sed. I read a lot of guides and discussions, but none of them helped. I have a xml file, and I need to delete more occurences of these three lines:

<function type="class">
   <arg name="class.name">com.mycompany.name.UnLockIssueFunction</arg>
</function>

我只想删除<function>之间的部分,但是有更多这样的标签.我的xml文件看起来像这样

I wanted to use deleting just the part between <function>, but there is more of this tags. My xml file looks like this

<post-functions>
  <function type="class">
    <arg name="class.name">com.mycompany.name.function.issue.UpdateIssueStatusFunction</arg>
  </function>
  <function type="class">
    <arg name="class.name">com.mycompany.name.function.misc.CreateCommentFunction</arg>
  </function>
  <function type="class">
    <arg name="class.name">com.mycompany.name.function.issue.GenerateChangeHistoryFunction</arg>
  </function>
  <function type="class">
    <arg name="class.name">com.mycompany.name.function.issue.IssueReindexFunction</arg>
  </function>
  <function type="class">
    <arg name="class.name">com.mycompany.name.function.event.FireIssueEventFunction</arg>
    <arg name="eventTypeId">13</arg>
  </function>
  <function type="class">
    <arg name="class.name">com.mycompany.name.UnLockIssueFunction</arg>
  </function>
</post-functions>

推荐答案

这可能对您有用(GNU sed):

This might work for you (GNU sed):

sed '/<function type="class">/!b;N;N;/<function type="class">\s*\n\s*<arg name="class.name">com.mycompany.name.UnLockIssueFunction<\/arg>\s*\n\s*<\/function>/d' file

这篇关于sed删除多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆