How to generate seven-figure integer ranges with seq?

Viewed 56

I am baffled by seq:

seq 218000 218010

will generate integers from 218000 to 220000 as expected:

218000
218001
218002
218003
218004
218005
218006
218007
218008
218009
218010

whereas:

seq 2180000 2180010

will output

2.18e+06
2.18e+06
2.18e+06
2.18e+06
2.18e+06
2.18000e+06
2.18001e+06
2.18001e+06
2.18001e+06
2.18001e+06
2.18001e+06

How can I use seq to output seven-figure integers?

1 Answers

Reading the seq man page (man seq), you can control the output of the seq command using the -f flag, which accepts a C-style format string. The default format specifier is %g which explains why you are getting the exp print output for large numbers.

Ask seq to output a float without any decimal part:

seq -f'%.0f' 2180000 2180010

That should do what you want (tested on macOS and Ubuntu).

Alternatively, if you are using bash, you could also use the {0..10} style generator:

for i in {2180000..2180010}; do echo $i; done
Related