change list to comma seperated items

I have a list of servers in a file called serverlist like this

server1
server2
server3

i need to have them (with no trailing comma, the program does not like that)

server1,server2,server3

so far i have been using

HOSTS=/tmp/serverlist
HOSTS=${HOSTS:-$(grep -Ev "^#|^$" $HOSTS_LOCAL)}
HOSTS=$(echo $HOSTS |tr -s '\n ' ',,')
HOSTS=${HOSTS%,}

to achieve this. It works but is there a quicker easier way say like in one line. (I need the grep -Ev "^#|^$" because we have a lot and need to comment them out sometimes).

Sean

Yes :slight_smile:

% cat file
server1
server2
server3
% paste -sd, file
server1,server2,server3

The paste command worked great and did just what I was looking for. I appreciate the help.

Sean