Solved How join both curly braces commands?

The problem was the second possible 15 converting without the first possible 15 should it be a 15. The solution is "${string/#?15/${z/%15??/z}}", but then how can the first command "${string/%15/z}" also be included in the same curly braces?
Code:
string="15151"; # wrong z151 / 15z1 / zz1 > should be unchanged
string="11515"; # correct 1z15 / 115z / 1zz > should be changed

echo ${string/%15/z}
echo ${string/#?15/${z/%15??/z}}
 
Ok have now a solution, so it's impossible without awk.
Code:
arr="15151 15115 11115 11511 11515"
for a in $arr; do
    echo ${a:0:1}"."${a:1:2}"."${a:3:${a#}} | awk '{gsub(/\.15|15\./, "z"); gsub(/\./, ""); print $0}'
done
 
Back
Top