Sunday, October 30, 2022

[SOLVED] Generating numbers sequence containing leading zeros

Issue

I'm looking for a way to create a sequence of numbers with a number of leading zeros.

For example, starting from 00000001 to 1000000000.

I tried many variations of seq but I was never able to produce a sequence with starting number as indicated to go to the desired end number.

To generate a billion of numbers, seq would likely take 20min on my machine o printf which is a ton slower is likely not an option, I'm looking into achieving this with seq only for starters if possible.

Any ideas?


Solution

To generate a sequence with a specified format you have to use -f argument like this:

seq -f "%08g" 1000000000

Although you didn't specify how you want to use so large numbers it would be better to parallelize it to make a final solution efficient.

Edit: Version without shortest representation:

seq -f "%08.0f" 10000000


Answered By - Michal
Answer Checked By - David Marino (WPSolving Volunteer)