#! /local/bin/perl -s
#
# rec		--- join multi-line records and split them
#
# Assumes records are separated by a blank line.  Joined
# records are printed on single lines, with a ^A (\01)
# separating the lines of the record.  The expander simply
# translates them back to newlines.
#
# This was once useful for rsort and rgrep (before perl).
#
# Author: Oscar Nierstrasz (Revised: 11/10/88)

$usg = 'Usage :	rec -j(oin) [<file> ...]
	rec -s(plit) [<file> ...]
	rec -d(elete empty records) [<file> ...]
';

# -c and -x are given as synonyms for -s and -j:

if ($j || $c) {
	$/ = "";
	while (<>) {
		# translate all but final \n to ^A:
		chop;
		s/\n/\01/g;
		print "$_\n";
	}
}
elsif ($s || $x) {
	while (<>) {
		# translate back:
		tr/\01/\012/;
		print;
	}
}
else { die $usg; }

__END__

