I have a series of numbers of different lengths (varying from 1 to 6 digits) within some text. I want to equalize the lenghts of all these numbers by padding shorter numbers by zeros.
E.g. The following 4 lines -
A1:11
A2:112
A3:223333
A4:1333
A5:19333
A6:4
Should become padded integers
A1:000011
A2:000112
A3:223333
A4:001333
A5:019333
A6:000004
I am using "sed" and the following combersome expression:
sed -e 's/:([0-9]{1})>/:000001/'
-e 's/:([0-9]{2})>/:00001/'
-e 's/:([0-9]{3})>/:0001/'
-e 's/:([0-9]{4})>/:001/'
-e 's/:([0-9]{5})>/:01/'
Is it possible to do this in a better expression than this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…