title: Add text to specific blocks defined by some special characters in sed
body: <p>I have hundreds of books in text format, which will be converted to epub and pdf with pandoc. Each text file contains plain text and poems. Aligning poems is a repeated task. Every second line of each poem needs to be intended. I need to add some special character at every other line of each poem, say, <code>==</code>. </p>
  
  <p>My question is:</p>
  
  <pre><code>here are some text  
  
  poem line 1  
  poem line 2  
  poem line 3  
  poem line 4  
  
  here are some text
  
  poem line 1  
  poem line 2  
  </code></pre>
  
  <p>I need output  </p>
  
  <pre><code>here are some text  
  
  poem line 1  
  ==poem line 2  
  
  here are some text  
  
  poem line 1  
  ==poem line 2  
  poem line 3  
  ==poem line 4  
  </code></pre>
  
  <p>My idea is:</p>
  
  <p>If we define poem blocks by some special character like</p>
  
  <pre><code>~   
  poem line 1  
  poem line 2  
  ~~  
  
  ~  
  poem line 1  
  poem line 2  
  poem line 3  
  poem line 4  
  ~~  
  </code></pre>
  
  <p>sed finds this <code>~</code> and adds <code>==</code> at each 3+2 lines and ended with <code>~~</code>.</p>
  
  <p>output should like this  </p>
  
  <pre><code>~   
  poem line 1  
  == poem line 2  
  ~~  
  
  ~  
  poem line 1  
  == poem line 2  
  poem line 3  
  == poem line 4  
  ~~  
  </code></pre>
  
  <p>Is it possible to do with sed or awk or any other scripts?</p>
  
  <p><a href="http://xensoft.com/use-sed-to-insert-text-every-n-lines-characters/" rel="nofollow noreferrer">http://xensoft.com/use-sed-to-insert-text-every-n-lines-characters/</a></p>