Description
In the datafile:
  • Every three non-blank lines constitute a data record.
  • Non-blank lines may be separated by none, one or more blank lines.

What we want is joining lines constitute a data record to one line, separating them by '|'s.

Raw Input Desired Output
John Doe
123 Main St Anytown, CT 06203
Mickey Mouse

11223 132nd Ave

Anaheim, CA 91004 Alfred E Neumann
47 Ironic Drive

Intercourse, PA 09342
John Doe|123 Main St|Anytown, CT 06203
Mickey Mouse|11223 132nd Ave|Anaheim, CA 91004
Alfred E Neumann|47 Ironic Drive|Intercourse, PA 09342
Script and Comments
Script1
[ 1] /^$/d
[ 2] :loop
[ 3] N
[ 4] /^([^\n]+\n+){2}[^\n]/!b loop
[ 5] s/\n+/|/g
Comments
  1. You have to use '-r' option of GNU sed to run this script to interpret REs as Extended REs.
  2. Step [1] is used to discard blank lines before a data unit.
  3. Step [2] thru [4] constitute a loop. This loop will repeat until there are three non-blank lines in Pattern Space. PS matches ([^\n]+\n+){2}[^\n] if it contains three non-blank lines.