#!/perl/bin/perl

use fileHandle;

my @files = @ARGV;
my ($file, $newfile, $line, $line_no, @columns, $cols);

foreach $file (@files)
{
	$newfile = "$file.crlf";

	print "Writing file: $file to new file: $newfile \n";

	open(OUTFILE, ">$newfile");

	my $FH = new FileHandle("$file");
	while ($line = <$FH>)
	{
		$line_no ++;

		chomp($line);

		@columns = split('\t', $line);

		$cols = @columns;

		if ($cols == 1) {
			print OUTFILE ("[CRLF] $line");
		}
		else {
			if ($cols > 2) {
				if($line_no > 1) {
					$line = "\n$line";
				}

				print OUTFILE ("$line");
			}
		}
	
	}

	print "\n";

	close(OUTFILE);
}

print "Processing Completed.\n";
