How to insert period after each number?

stupid question: trying to use sed to do the following...

$ echo '12345' | sed 's/./&./g'
1.2.3.4.5.

needed this instead: 1.2.3.4.5 but how? please advise

Like this?

echo "12345" | sed 's/./&./g;s/\.$//'
1.2.3.4.5
1 Like

Try like..

echo "12345" |sed 's/./&./g;s/.$//' 
1 Like

thanks.. got it working using either:

$ echo '12345' | sed "s/./&./g;s/\.$//"
1.2.3.4.5

$ echo '12345' | sed "s/./&./g;s/.$//"
1.2.3.4.5

One more

echo "12345" | awk -F "" ' {for(i=1;i<=NF;i++){printf("%s%s",$i,i%1?"":".")}}'|awk '{sub(/.$/,"")};1' 

Some awks can do this:

echo "12345" | awk '$1=$1' FS= OFS=.

Slight modification to Scrutinizer's solution to handle the case of strings starting with zero:

echo "12345"| awk '{$1=$1}1' FS= OFS=.

In perl:

$ echo '12345' | perl -pe 's/(.)(?!$)/\1./g'
1.2.3.4.5
$

Search for characters that are not followed by the end of the line, and add a period after them.