I’d like to insert the line
<hr />
above every occurrence of a header 2 line in a file – e.g., above this pattern
<h2>variable pattern here</h2>
So the above should become
<hr />
<h2>variable pattern here</h2>
How can I do this with Vim, Sed or Perl?
With
sedyou could dosed '/<h2>/i <hr />':The first part
/<h2>/matches line containing<h2>and the second part uses theicommand to insert<hr />above the matched line.A nice option with
sedis-ithis save the changes back to the file instead of printing tostdoutbut be sure that the changes are correct first.