Jamalissimo
Jamalissimo

Reputation: 127

sed delete multiple lines

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>

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>

Upvotes: 1

Views: 897

Answers (2)

Jeff Ferland
Jeff Ferland

Reputation: 18292

When you get into fancier editing, fancier editors may help. Try reading up on scripting in VIM and take a look at these questions:

Search and delete multiple lines

VIM: globally match line, delete this and 2 following lines

Upvotes: 1

potong
potong

Reputation: 58381

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

Upvotes: 2

Related Questions