There are many ways to left pad numbers in Linux. Usually this seems to be done by adding leading zeros in front of the main number. A few examples of doing this can be seen below:
1
2
3
4
5
6
7
|
# left pad with zeros
printf "%05d\n" 99
> 00099
# left pad with zeros and other text
printf "my-file-name-%05d.txt\n" 99
> my-file-name-00099.txt
|
1
2
3
|
# left pad with zeros using awk
echo 99 | awk '{printf "%05d\n", $0}'
> 00099
|
1
2
3
4
5
6
7
8
9
10
|
# left pad with zeros bash loop
for i in {00001..00005}; do
echo $i
done
> 00001
> 00002
> 00003
> 00004
> 00005
|
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment