Append the text file with comma at the end of every word

Hi folks,

Using shell, I am trying the append comma to every line of text.
the requirement is like, I have to open the txt file in unix and read line by line and should add comma at the end of every word to make it single line

txt file
-------
abc@gmail.com
bcd@gmail.com
efg@gmail.com
ghi@yahoo.com

Now the file should be seperated with comma as shown below
-----------------------------------------------------------

abc@gmail.com,bcd@gmail.com,efg@gmail.com,ghi@yahoo.com

Please help me.......

You don't need to add new data, just change what's already there. Linefeeds can be changed into commas easily enough:
tr '\n' ',' < input > output

That might add a comma to the end, though. so tr '\n' ',' < input | sed 's/,$//' > output

Thanks alot coronaa688 ..
But can you please eloborate it... What is input n output here ..

Thanks in advance ...

input is the input file, output is the output file. They shouldn't be the same, since most UNIX utilities can't edit in-place.

input and output are nothing but your "input" text file where the email id's exists and output is the file where you want to save the outcome.

Alternatively:

paste -sd, input > output

Regards,
Alister

Awk solution..

awk '{NR==1?s=$0 : s=s","$0}END{print s}'  inputfile
 
perl -0pe 's/\n/,/g' input