Merging lines based on occurances of a particular character in a file

Hi,

Is there any way to merge two lines based on specific occurance of a character in a file.

 I am having a flat file which contains multiple records.

Each row in the file should contain specified number of delimiter.
For a particular row , if the delimiter count is not matched with the specified count, then then next row should be merged with the previous row. Again the same check has to be done.

The script should accept number of occurances of a particular delimiter as the parameter.

For Example if the number of occurances of comma in every line is 5 in a flat file

Sample Input

   1,2,3,
   4,5,6
   a,b,c,d,e,f
   10,20,30
   ,40,50,60
   11,22
   ,33
    ,44,
    55,
    66

Output (Each row should contain 5 commas)

     1,2,3,4,5,6
     a,b,c,d,e,f
     10,20,30,40,50,60
     11,22,33,44,55,66

Mohan

$ awk '
BEGIN {
FS=",";
maxFLD=6;
}
{
while (NF < maxFLD || $0 ~ /\,$/ ) {
getline record;
$0 = $0 record
}
print $0
}
' mt.txt

//Jadu

This works fine if the word is not splitted in two lines.

But it a word is splitted in two lines it is not working.

Sample input

one,two,three,
four,five
six,se
ven,eight,nine,ten
eleven,twelve,thirteen,fourteen,fif
teen
1,2,3,4,5

output (Contains 4 commas in each line)

one,two,three,four,five
six,seven,eight,nine,ten
eleven,twelve,thirteen,fourteen,fifteen
1,2,3,4,5