批处理去除指定字符前所有的0

题目

有文本 1.txt

0000acb0h
0b0c00a000s
0000h00ga00
a0000000

要求

通过批处理将文本所有字符串字符a前的0去除输出如下

acb0h
bca000s
hga00
a0000000

编写代码
#! /bin/bash

file=./1.txt
before=a
replace=0

while read line
do
        len=${#line}

        i=0
        str=            #保留指定字符前面字符

        while [ ${i} -lt ${len} ]
        do
                c=${line:${i}:1}

                #判断是否在指定字符之前
                if [ "${c}" == "${before}" ]
                then 
                        break
                fi

                #是否为需要删除的字符
                if [ "${c}" != "${replace}" ]
                then
                        str=${str}${c}
                fi

                let i++
        done

        # 保留指定字符后面的内容
        suffix=${line:${i}}

        echo ${str}${suffix}


done < ${file}
运行结果

这里写图片描述