#!/lang/perl
# note: this assumes the records file is well-formed, as output from table2records
# TODO write another version which copes with different tags (field names / keys -
# what is a good word for this?) in each record
# and different orders of tags, etc.

# read 1st record, then output tags line and the record
while (1) {
	$line = <STDIN>;
	chomp $line;
	last if $line eq "";
	($k, $v) = split /\t/, $line;
	push @k, $k;
	push @v, $v;
}
exit if !defined $line;
print join "\t", @k; print "\n";
print join "\t", @v; print "\n";

# rest of the records
while (1) {
	my @v;
	while (1) {
		$line = <STDIN>;
		chomp $line;
		last if $line eq "";
		($k, $v) = split /\t/, $line;
		push @v, $v;
	}
	last if !defined $line;
	print join "\t", @v; print "\n";
}
