vi or vim replace ,$ (eol) with just a comma

I have lines in a file like this (140,000+ entries):

value1,
value2,
value3,
"
"

I want to concatenate the three (there are 22) lines with commas so it looks like this

value1, value2, value3
"
"

I'm trying with
:g/,$/s/,$/, /g

but that is not flying.

any ideas?

Thanks, Dan

If you want to collapse every three lines into one, you could try:
cat myfile | paste - - -

1 Like

Unfortunately, it is a variable number of items 22-41. So I need to remove the end of line for every line that has a comma. Thanks for the thought though. -Dan

Weeellllll, ok MS Word lets you replace comma + ^013 which takes a comma plus the carriage returns/line feeds/^M and leave just the comma and concatenates any line which had previously a comma (or any other character) and a new line. Sure takes a long time, and much CPU. At least it works.

Would still like to know how to do this in vi or vim, as I remember needing this before. Thanks, Dan

I know there's an example of something like it in the sed & awk book.
But this will work from the command line:
cat myfile | while read s
do
case "$s" in
*,) printf "%s" s;;
*) echo $s;;
esac
done

Try

g/,$/.,+2j

I know the Thread is kind of old already, but for who might get this page in a search, here is a other fast alternative:

:%s/,\n/,/g

works for me in a VIM 7.1 f/ windows <== irgh :mad: