Questions tagged [seq]

Use for questions related to "seq", a command-line tool to print sequences of numbers.

seq is a command-line tool, available for example in the GNU core utilities which is used to print a sequence of numbers. The start value, end value, increment and separator character can be chosen via command-line arguments.

Its original use stems from the time when shells had no other possibility to iterate over a range of numbers in a for loop; it would then be used in constructs such as

for i in $(seq 1 10); do .... ; done

However, since this creates a list of all numbers to iterate over in advance and is therefore rather inefficient, it has become somewhat obsolete with the advent of shells that provide C-style loop syntax with on-the-fly increment. Also, the Bash shell provides a builtin expansion mechanism that achieves the same without calling an external tool.

One of the primary incentives to use it nowadays is that it allows to generate lists of floating-point numbers - a feature difficult to perform natively in most shells, which are only capable of integer arithmetic. In addition, it accepts printf style formatting instructions for finer output control.

41 questions
51
votes
8 answers

How to display numbers in reverse order using seq(1)?

I have iterate over numbers in various order. I am able to display them in increasing order, even with steps like: $ seq --separator="," 1 10 1,2,3,4,5,6,7,8,9,10 $ seq --separator="," 1 2 10 1,3,5,7,9 I am also able to display them in reverse…
mtk
  • 26,802
  • 35
  • 91
  • 130
33
votes
5 answers

Bash - Sequence of numbers in the same line

I know the command seq to generate sequence of integers, one per line, but I would like to ask two questions: Is it possible to write the numbers of the sequence in the same line? Is it possible to create a string made of the sequence of numbers…
Salsiccio
  • 431
  • 1
  • 4
  • 3
14
votes
5 answers

Portable POSIX shell alternative to GNU seq(1)?

I've noticed you can't really count on seq(1) being available on anything but GNU systems. What's a simple reimplementation of seq(1) I can bring with me written in POSIX (not bash) shell? EDIT: Note that I intend to use it on at least various…
Elizafox
  • 796
  • 6
  • 15
12
votes
5 answers

How to randomize the output from seq?

I know I can use seq to generate a random list of numbers: 1, 2, 3, 4... I want to get those numbers into a random order like 3, 1, 4, 2... I know I can use shuf to shuffle the lines of a file. So I could use seq to write random numbers to a file…
bernie2436
  • 6,505
  • 22
  • 58
  • 69
8
votes
7 answers

How to avoid printing a newline when seq completes?

To create a column header, looking like: 1234567890123456789 I (am trying to) use seq and echo: seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9 However, seq outputs a newline after each run. How can I avoid that?
GreenMatt
  • 695
  • 6
  • 16
7
votes
8 answers

Generate two sequences of numbers separated by "|"

I'm using bash (CentOS 5) and looking to generate this output (I assume I could use seq or echo together maybe?): 1|1, 2|2, 3|3, .... 31|31, 32|32, 33|33, I googled seq examples for over two hours and the closest I can come up with is: echo…
James Gaul
  • 127
  • 8
6
votes
1 answer

seq decimal separator

Using a seq command with floating point numbers, my output comes with commas instead of dots as decimal separators, despite using dots in the input: seq 0.1 0.3 1.3 0,1 0,4 0,7 1,0 1,3 I assumed this to be linked with the locale LC_NUMERIC, which…
FelixJN
  • 12,616
  • 2
  • 27
  • 48
6
votes
1 answer

nesting brace expansion and command substitution

I want to create a simple bash-script that checks whether a directory contains all the files whose names contain numbers from 1 to N. # Creating some files for testing $ cd /tmp/ $ mkdir test $ touch test/a01x.dat $ touch test/b02y.dat # Display…
ka3ak
  • 1,235
  • 4
  • 18
  • 30
6
votes
1 answer

How do I make BSD seq not output + and e when using large numbers?

Say I run seq 4000000 4100000, I want seq print the numbers, as quoted from the man page, "from first (default 1), to near last as possible". Just like the GNU seq does. But the output of my command is…
DisplayName
  • 11,468
  • 20
  • 73
  • 115
5
votes
2 answers

`seq` and bash brace expansion failing

IINM my system is failing when bashing for i in {0..10000000}; # Seven zeroes. do false; done # `bash` exited and its `tmux` pane/window was closed. or for i in $(seq 0 10000000); # Seven zeroes. do false; done # `bash` exited and…
41754
  • 85
  • 1
  • 7
  • 19
3
votes
3 answers

Bash function: Execute $@ command with each argument in sequence executed separately

This is an example function: function example { echo "TextBefore $@ TextAfter" ; } This is the command using the function: example A{1..5}B The output: TextBefore A1B A2B A3B A4B A5B TextAfter How I want it to be: TextBefore A1B…
neverMind9
  • 1,680
  • 2
  • 18
  • 38
3
votes
1 answer

seq - invalid floating point argument error

I have a file with many numbers, with each number on one line. My goal is to find the numbers that are missing. I'm trying to generate the sequence of all the numbers with seq start=$(head -1 numbers.txt) finish=$(tail -1 numbers.txt) seq $start…
nikhil
  • 992
  • 2
  • 10
  • 16
3
votes
6 answers

Add consecutive numbers succintly and elegantly to index lines

I usually do this $ wc questions 33 36 3105 questions $ seq 1 33 > nums $ paste nums questions 1 Content 2 ... . . 33 End Content but I feel there could be faster way to do this, without the bad-looking dummy file. How with…
user2362
3
votes
3 answers

printing a series of characters

My ultimate goal here is to generate a block of text that can be used to test out various fonts at a terminal. I want to generate the file as basically an ascii chart. A series of characters from 1 to 255 will do, I'm not worried about bells, or…
slf
  • 133
  • 4
3
votes
2 answers

Can I use seq to go from 001 to 999?

Can I use seq to go from 001 to 999?
JoeS
  • 141
  • 1
  • 4
1
2 3