Convert columns to single row

Hello all

I have data like

1
2
3
4
5

I wish my output would be like

1,2,3,4,5

For this i have executed

'BEGIN {FS="\n"; ORS=","} {print $0}' test

and got the output as

1,2,3,4,5,

I do not want to have , at the end of 5. output should be like

1,2,3,4,5

If the input is

1
2
3

then output should be like 1,2,3

Please reply

paste -sd, infile
paste -s -d, inputfilename 

Thankyou verymuch

Its working.

awk '{printf ((NR-1&&NF)?",":x)$0}' file

Try:

xargs < file | tr ' ' ','