Question

I have a file:

fakdfal
14867
kgjafdfrf
8423685

I want to get the result:

fakd.fal
14.867
kgjafd.frf
8423.685
Était-ce utile?

La solution

Using awk:

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

Using sed:

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

Autres conseils

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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top