How to eliminate trailing comma's from the output of a text file

Hope some one can guide me.

Background:

I have a protocol that generates a comma delimited text file (without columns/headers). The file gets generated out of two separate data streams/pipes. The first data stream produces an output of 30 fields/columns and the second one generates the output with only 4 fields/columns. As a result, the data from the second data stream shows trailing commas. Attached screenshot depicts the issue.

How can i get rid of those additional commas from being generated only from the second data stream. It supposed to output only those 4 fields without any trailing commas. I guess because the first data stream has more fields, causing the second data stream to stretch the columns to match.

Hope i explained the issue well. If not please let me know if you need any additional information.

Attached the image file for illustration purposes.

Trailing Commas in the Datastream.jpg

Thanks,

BN.