#!/bin/sh

# This script "packs" the paragraphs (blocks of characters separated
# from others by at least two consecutive carriage returns) of the
# standard input and place the result on standard output.  Instead of
# standard input, you may use the results of concatenating a bunch of
# files by giving them as command line arguments.

# The packing is done so as to leave lines of each paragraph separated
# only by an underscore and the packed paragraphs separated from one
# another by single carriage returns.  In case the original file
# contained any underscores, all underscores in the original are first
# changed to ^G characters; the inverse script "unpackpars" changes ^G
# characters back to underscores.  (If the original file contains ^G
# characters, you'll need to change them to something else temporarily.)

cat $* | (tr '_' '\007'; echo '') | (echo ''; sed 's+^$+_+') | (tr '\012_' '_\012'; echo '') | grep -v '^_$' -a
