Search code examples
bashshelllargenumber

Generating huge lists of numbers


I'm trying to generate a huge list of sequenced numbers with 0 padding

 for example:
 00000000
 00000001
 00000002
 .
 .
 99999997
 99999998
 99999999

im trying something like:

 for i in $(seq 00000000 99999999);do echo ${i} >> filelist.txt;done

this has two problems.

 1: the range is too big and the system cant handle it
 2: the numbers arent padded so I end up with something like this:

 1
 2
 3
 .
 .
 998
 999
 1000

Solution

  • seq already knows how to do padding.

    seq -w 00000000 00000009 >filelist.txt
    

    There's also -f for more general formats (mostly useful when the increment isn't an integer). For more complex output, the best solution would be to postprocess the output of seq with sed or other text processing tools.