[root@localhost sh]# str=00007985566465
[root@localhost sh]# str_new=$(echo -e $str | sed -r 's/0*([0-9])/\1/')
[root@localhost sh]# echo $str_new
7985566465
本文介绍了一种使用 Bash 脚本和 sed 命令去除字符串中前导零的方法。通过具体的 shell 命令展示如何将带有前导零的数字字符串转换为正常数字格式。
[root@localhost sh]# str=00007985566465
[root@localhost sh]# str_new=$(echo -e $str | sed -r 's/0*([0-9])/\1/')
[root@localhost sh]# echo $str_new
7985566465

被折叠的 条评论
为什么被折叠?