4

I'm trying to create a file with all the numbers up 75 million on every line.

I'm typing in my terminal using Bash:

seq 1 75000000 > myfile.csv

But anything above 1 million gets turned into scientific notation and I'd want everything as integer (i.e. 7.31896e+07)

Do you have any idea how to achieve this?

FinanceGardener
  • 188
  • 2
  • 17
  • 1
    You have an environment setting somewhere. I can do `seq 74999995 75000000` and it is all still integer values. I don't know what offhand, other than `LOCALE` would control the default here. – David C. Rankin Nov 09 '17 at 23:51
  • Please run `type seq` and report the results. – John1024 Nov 10 '17 at 00:26

2 Answers2

7

seq can take a printf-style format string to control its output. f format with a "precision" of 0 (i.e. nothing after the decimal point, which leaves off the decimal point itself) should do what you want:

$ seq 74999998 75000000
7.5e+07
7.5e+07
7.5e+07
$ seq -f %1.0f  74999998 75000000
74999998
74999999
75000000
Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
1

Observe that this produces integers:

$ seq  74999998 75000000
74999998
74999999
75000000

While this produces floating point numbers:

$ seq -f '%.5g' 74999998 75000000
7.5e+07
7.5e+07
7.5e+07

The output format of seq is controlled by the -f options.

How is the -f option being applied in your case? One possibility is that your shell has an alias defined for seq that applies this option. For example:

$ alias seq="seq -f '%.5g'"
$ seq 74999998 75000000
7.5e+07
7.5e+07
7.5e+07

You can determine if this is the case by running bash's builtin type command:

$ type seq
seq is aliased to `seq -f '%.5g''

Documentation

From man seq:

   -f, --format=FORMAT
          use printf style floating-point FORMAT
John1024
  • 109,961
  • 14
  • 137
  • 171
  • 1
    That's interesting - no alias in my case though `type seq` yields `seq is hashed (/usr/bin/seq)` so still unclear why I had that scientific formatting by default – FinanceGardener Nov 10 '17 at 02:31