I'm programming a bash script that pads one-digit, two-digit and three-digit numbers with zeros. For example:
file.txt
:
2
22
222
2222
a2a2
2a2a
a22a
2aa2
22a2
output.txt
:
0002
0022
0222
2222
a0002a0002
0002a0002a
a00022a
0002aa0002
0022a0002
The purpose of this script is to fill the digits until they reach a maximum of 4 digits.
I have to do it with the sed
command. I thought about doing it like this, but it doesn't work like I want.
sed -r -i 's/[0-9]{1}/0&/g' file.txt