title: SED to spit out nth and (n+1)th lines
body: <p>EDITS: For reference, "stuff" is a general variable, as is "KEEP".
  KEEP could be "Hi, my name is Dave" on line 2 and "I love pie" on line 7. The numbers I've put here are for illustration only and DO NOT show up in the data.</p>
  
  <p>I had a file that needed to be parsed, keeping every 4th line, starting at the 3rd line. In other words, it looked like this:</p>
  
  <pre><code>1 stuff
  2 stuff
  3 KEEP
  4 
  5 stuff
  6 stuff
  7 KEEP
  8 stuff etc...
  </code></pre>
  
  <p>Great, sed solved that easily with:</p>
  
  <pre><code>sed -n -e 3~4p myfile
  </code></pre>
  
  <p>giving me</p>
  
  <pre><code>3 KEEP
  7 KEEP
  11 KEEP
  </code></pre>
  
  <p>Now I have a different file format and a different take on the pattern:</p>
  
  <pre><code>1 stuff
  2 KEEP
  3 KEEP
  4
  5 stuff
  6 KEEP
  7 KEEP etc...
  </code></pre>
  
  <p>and I still want the output of</p>
  
  <pre><code>2 KEEP
  3 KEEP
  6 KEEP
  7 KEEP
  10 KEEP
  11 KEEP
  </code></pre>
  
  <p>Here's the problem - this is a multi-pattern "pattern" for sed. It's "every 4th line, spit out 2 lines, but start at line 2". </p>
  
  <p>Do I need to have some sort of DO/FOR loop in my sed, or do I need a different command like awk or grep? Thus far, I have tried formats like:</p>
  
  <pre><code>sed -n -e '3~4p;4~4p' myfile
  </code></pre>
  
  <p>and</p>
  
  <pre><code>awk 'NR % 3 == 0 || NR % 4 ==0' myfile
  </code></pre>
  
  <p>and</p>
  
  <pre><code>sed -n -e '3~1p;4~4p' myfile
  </code></pre>
  
  <p>and</p>
  
  <pre><code>awk 'NR % 1 == 0 || NR % 4 ==0' myfile
  </code></pre>
  
  <p>source: <a href="https://superuser.com/questions/396536/how-to-keep-only-every-nth-line-of-a-file">https://superuser.com/questions/396536/how-to-keep-only-every-nth-line-of-a-file</a></p>