You can just replace the space
with ,
using sed
if there are no other contents with space in the file. Else, edit your question with more details.
sed 's/ /,/g' File
If it is not file content, use this:
sed 's/ /,/g' <<< $string #string is the variable with the IP string
EDIT:
AMD$ cat File
'114.124.35.252'
'114.79.61.186'
'39.225.242.17'
'202.62.16.29'
1.You can use tr
(this will replace the last newline with ,
as well. See man tr
for details)
AMD$ tr '\n', ',' < File
'114.124.35.252','114.79.61.186','39.225.242.17','202.62.16.29',
2.Else, you can use this awk
command:
AMD$ awk -v n=$(wc -l < File) '{if(NR!=n){ORS=","}else{ORS="\n"}}1' File
'114.124.35.252','114.79.61.186','39.225.242.17','202.62.16.29'
The default record seperator for awk
is '\n'
. Change this to ,
for all but the last line.