title: How to combine three consecutive lines of text file in sed?
body: <p>I have a file, that consists of a repeating sequence of three lines, that I want to merge together. Put in other words, I'd like to replace every but third <code>\n</code> into space. E.g. I'd like the transform input</p>
  
  <pre><code> href="file:///home/adam/MyDocs/some_file.pdf"
   visited="2013-06-02T20:40:06Z"
   exec="'firefox %u'"
   href="file:///home/adam/Desktop/FreeRDP-WebConnect-1.0.0.167-Setup.exe"
   visited="2013-06-03T08:50:37Z"
   exec="'firefox %u'"
   href="file:///home/adam/Friends/contact.txt"
   visited="2013-06-03T16:01:16Z"
   exec="'gedit %u'"
   href="file:///home/adam/Pictures/Screenshot%20from%202013-06-03%2019:10:36.png"
   visited="2013-06-03T17:10:36Z"
   exec="'eog %u'"
  </code></pre>
  
  <p>into  </p>
  
  <pre><code> href="file:///home/adam/MyDocs/some_file.pdf" visited="2013-06-02T20:40:06Z" exec="'firefox %u'"
   href="file:///home/adam/Desktop/FreeRDP-WebConnect-1.0.0.167-Setup.exe" visited="2013-06-03T08:50:37Z" exec="'firefox %u'"
   href="file:///home/adam/Friends/contact.txt" visited="2013-06-03T16:01:16Z" exec="'gedit %u'"
   href="file:///home/adam/Pictures/Screenshot%20from%202013-06-03%2019:10:36.png" visited="2013-06-03T17:10:36Z" exec="'eog %u'"
  </code></pre>
  
  <p>Unfortunately the file is rather long, so I'd prefer not to load the whole file into memory and not to write to result back into file - just print the concatenated lines into the standard output so I can pipe it further.</p>
  
  <p>I know that <em>potentially</em> <code>sed</code> might just work for it, but after I had given it a honest try, I am still at square one; the learning curve is just too steep for me. :-(</p>
  
  <hr>
  
  <p>I did a rough benchmarking and I found out, that the <code>sed</code> variant is almost twice as fast.</p>
  
  <pre><code>time awk '{ printf "%s", $0; if (NR % 3 == 0) print ""; else printf " " }' out.txt &gt;/dev/null
  
  real    0m1.893s
  user    0m1.860s
  sys     0m0.028s
  </code></pre>
  
  <p>and</p>
  
  <pre><code>time cat out.txt | sed 'N;N;s/\n/ /g' &gt; /dev/null
  
  real    0m1.360s
  user    0m1.264s
  sys    0m0.236s
  </code></pre>
  
  <p>It is interesting: why does <code>sed</code> require more kernel time than <code>awk</code>?</p>
  
  <p>The out.txt is 200MB long and the processor is Intel(R) Core(TM) i7-3610QM CPU @ 2.30GHz on Linux-Mint 14 with kernel 3.8.13-030813-generic.</p>
  
  <hr>
  
  <p>I need this in my effort to parse the <code>recently-used.xbel</code>, the recently opened files list in the Cinnamon</p>
  
  <p>If you came here for this specific problem, this line should help you:</p>
  
  <pre><code>xpath -q  -e "//bookmark[*]/@href | //bookmark[*]/@visited | //bookmark[*]/info/metadata/bookmark:applications[1]/bookmark:application[1]/@exec"  recently-used.xbel | sed 's/href="\(.*\)"/"\1"/;N;s/visited="\(.*\)"/\1/;N;s/exec="\(.*\)"/"\1"/;s/\n/ /g' | xargs -n3 whatever-script-you-write 
  </code></pre>