Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文件:
fakdfal 14867 kgjafdfrf 8423685
我想得到结果:
fakd.fal 14.867 kgjafd.frf 8423.685
使用awk:
awk
awk '{sub(/...$/, ".&"); print}'
使用sed:
sed
sed 's/...$/.&/'
使用 sed 更简单:
sed -i.bak 's/...$/.&/' file
或 awk 解决方案:
awk 'length($0)> 3 {l=length($0); $0=substr($0, 1, l-3) "." substr($0, l-2)} 1' file