#!/usr/npac/bin/perl

#/usr/local/bin/perl
$filename='tqfile.txt';

open(FILE1,"$filename");
$yes = 0;
$n = 0;
while (<FILE1>) {
        chop;
	$this = $_;
	#print $this;
	if (($this =~ /"(\d+)","(.*)","(...)","(.*)$/) || ($this =~ /"(\d+)",(.*),"(...)","(.*)$/)){
		if ($n != 0) {
			$doc =~ s///g;
			#$doc =~ s/\n//g;
			$doc =~ s/^(.*)"$/$1/;
			if ($title eq "") { $title = 'No title';}
			print "\"$tid\",\"$title\",\"$cart\",\"$doc\"\n";
		}
		#if ($yes == 1) {
		#	print "\"$tid\",\"$title\",\"$cart\",\"$doc\"\n"; 
		#}
		#$yes = 0;
		$tid = $1;
		$cart = $3;
		$title = $2;
		$doc = $4;
	}
	else {
		$doc .= ' ' . $this;
		#$yes = 1;
	}
	$n++;
}
### last one
if ($n != 0) {
	$doc =~ s///g;
	$doc =~ s/^(.*)"$/$1/;
	if ($title eq "") { $title = 'No title';}
		print "\"$tid\",\"$title\",\"$cart\",\"$doc\"\n";
}
$n++;
close(FILE1);

exit;
