Raw Input Desired Output
line 1
line 2
line 3
line 4 line 5 line 6
line 7
line 1<br>
line 2
line 3
line 4<br> line 5<br> line 6
line 7
Script and Comments
Script1
[ 1] $!N
[ 2] s/\(.\)\(\n.\)/\1<br>\2/
[ 3] P
[ 4] D
Comments
  1. Pattern Space is abbreviated to `PS'.
  2. In each iteration, we join the next line to PS except the last line of the datafile.
  3. After Step [1], there will be two lines in PS. If both of them are non-blank, Step [2] will add a <br> tag to the end of the first line.
  4. Step [3] is used to print the first line of PS, and
  5. Step [4] is used to delete the first line of PS, then make sed branch to the first command of the script.