Add a comma at end of every line

hello

A small shell scripting help..

I have a file say with 5 lines of text (text file).
At the end of everyline I need to add a comma at the end of the file.

Thanks, ST2000

sed "s/$/,/g" filename

Thanks a lot ..

I can only display a comma at the end of line and pipe it to new file, but how can i do that inside the file and retain the same name as well.. When I do on same file, it will simply erase it.

Moreover I dont need the comma only in the last line..

Thanks, ST2000

ed filename <<EOF
%s/$/,/
$
s/,$//
w
q
EOF

Not sure, cannot test it right now ...

You may be familiar with using 'vi'...in which case you can open a file using vi...manipulate as required then save the changes and you have amended the file.

You can actually do this both from the command line or using 'vi' or another editor like ed. From the command line you will have to direct output to another file and then rename the file back....this code would do it for you...

sed -e 's/$/,/g' -e '$ s/,$//' your_file > new_file && mv new_file your_file