生成庞大的数字列表

时间:2011-06-22 21:16:08

标签: bash scripting operations largenumber

我正在尝试生成一个包含0填充的大量序列号

 for example:
 00000000
 00000001
 00000002
 .
 .
 99999997
 99999998
 99999999
我正在尝试类似的事情:

 for i in $(seq 00000000 99999999);do echo ${i} >> filelist.txt;done
这有两个问题。

 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

任何帮助将不胜感激..

2 个答案:

答案 0 :(得分:4)

seq已经知道如何填充。

seq -w 00000000 00000009 >filelist.txt

对于更多通用格式,还有-f(当增量不是整数时,这种格式非常有用)。对于更复杂的输出,最好的解决方案是使用seq或其他文本处理工具对sed的输出进行后处理。

答案 1 :(得分:0)

如何分两步完成此操作

seq 10 > file

while read i; do printf "%.8d\n" $i; done < file
00000001
00000002
00000003
00000004
00000005
00000006
00000007
00000008
00000009
00000010
相关问题