2

Suppose I have these two numbers: 800000 and 3200000. I want to find five numbers with an even difference in between these two numbers. Therefore, I want the output to be:

800000
1200000
1600000
2000000
2400000
2800000
3200000

I know about the seq command but I'm not sure how to do this.

3
  • You need to specify the increment for seq. Use something like $(( (3200000 - 800000) / 6 )) as your incremental value.
    – doneal24
    Jun 16 at 17:39
  • seq 800000 $(((3200000-800000)/6)) 3200000
    – choroba
    Jun 16 at 17:43
  • If the number of values does not divide exactly into the range, the spacing get rounded and the last value may not appear at all. Jun 16 at 19:04

2 Answers 2

4

Using jot:

$ jot 7 800000 3200000
800000
1200000
1600000
2000000
2400000
2800000
3200000

The jot utility is available by default on most BSD systems but may also be installed on, e.g., Debian GNU/Linux and Ubuntu Linux. The apt package containing jot seems to be called athena-jot.

1
  • Thanks. On Gentoo, I installed the jot package.
    – Amarakon
    Jun 17 at 0:05
0

Using any awk in any shell on every Unix box:

$ awk -v b=800000 -v e=3200000 -v n=5 'BEGIN{d=int((e-b)/(n+1)); for (i=b; i<e; i+=d) print i; print e}'
800000
1200000
1600000
2000000
2400000
2800000
3200000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.