With perl:
perl -pe 's/\n/, / unless eof' IP
Add the -i option to edit the file inplace. Or -i.orig to edit it in place but keep the original as IP.orig.
With the zsh shell, you can also load those IPs into an array with:
ips=( ${(f)"$(<IP)"} )
And then write them back joined with commas with:
print -r -- ${(j[, ])ips} > IP
Contrary to the perl one which processes one line at a time, that one loads the file whole in memory.
Two other differences:
- empty lines are discarded
- a newline character is always added at the end even if the original file didn't contain any like for an empty file or a file whose last line was not properly delimited.