sed command

Hi,
I have a variable say NUM="9.126.145.110"

I need to get the output as 9,126,145,110

I tried with sed command as sed s/\./,/ $NUM

But it didnt work

Please help..:confused:

sed -e's/\./,/g'

---------- Post updated at 01:03 PM ---------- Previous update was at 01:02 PM ----------

or it can be with $NUM as

echo $NUM|sed -e's/\./,/g'
1 Like
 echo $a | sed "s/\./,/g" 
1 Like

It works..

bash, ksh93:

echo ${NUM//./,}

and with the right locale:

printf "%'d\n" ${NUM//.}

--
Otherwise:

echo $NUM | sed 'y/./,/'
echo $NUM | tr . ,

You can also get rid of the pipe:

sed 'y/./,/' <<< $NUM
awk -F. '{$1=$1}1' OFS=, <<< $NUM