I need to pad strings with zeros until they reach a limit of four digits, for example:
1 -> 0001
44 -> 0044
555 -> 0555
1a -> 0001a
44b -> 0044b
565c -> 0565c
7890 -> 7890
I have a bash script and I add the file containing those numbers as a parameter.
#!/bin/bash
FILE=$1
if [ ! -f $FILE ]; then
exit 1
fi
sed -i 's/\<[0-9]\>/0&/g' $FILE
sed -i 's/\<[0-9][0-9]\>/0&/g' $FILE
sed -i 's/\<[0-9][0-9][0-9]\>/0&/g' $FILE
The script is not working on the 1a, 44b, 565c
. I don't know how to ignore the letters.