Domanda

I have a file:

fakdfal
14867
kgjafdfrf
8423685

I want to get the result:

fakd.fal
14.867
kgjafd.frf
8423.685
È stato utile?

Soluzione

Using awk:

awk '{sub(/...$/, ".&"); print}'

Using sed:

sed 's/...$/.&/'

Altri suggerimenti

Using sed it is simpler:

sed -i.bak 's/...$/.&/' file

OR awk solution:

awk 'length($0)> 3 {l=length($0); $0=substr($0, 1, l-3) "." substr($0, l-2)} 1' file
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top