Detailed Explanation of Linux seq Command

  • 2021-07-22 12:18:22
  • OfStack

01. Command Overview

The seq command is used to generate a sequence of integers.

02. Command format

Usage:


 seq [ Options ]...  Mantissa 
 seq [ Options ]...  First number   Mantissa 
 seq [ Options ]...  First number   Increment   Mantissa 

03. Common Options

Prints a number from the first number to the mantissa in a specified increment.


 -f, --format= Format     Use printf  Floating-point format of style 
 -s, --separator= String      Separate numbers with the specified string ( Default uses: \n)
 -w, --equal-width    Add before the column 0  So that the width is the same 
   --help       Display this help and exit 
   --version      Display version information and exit 

04. Reference example

4.1 Output 1-5


[deng@localhost ~]$ seq 5 
1
2
3
4
5
[deng@localhost ~]$ 

4.2 Output 1-5


[deng@localhost ~]$ seq 1 5
1
2
3
4
5
[deng@localhost ~]$ 

4.3 Output 3-5


[deng@localhost ~]$ seq 3 5 
3
4
5
[deng@localhost ~]$ 

4.4 Output 1 4 7 10


[deng@localhost ~]$ seq 1 3 10
1
4
7
10
[deng@localhost ~]$ 

4.5 Specify Format Output


[deng@localhost ~]$ seq -f "%3g" 9 11
 9
 10
 11
[deng@localhost ~]$ 

It means-f specifies the format, 3 digits after%, default is% g,% 3g places with insufficient digits are filled with spaces

4.6 Specifying Format Output


[deng@localhost ~]$ seq -f "%03g" 9 11
009
010
011
[deng@localhost ~]$ 

It means to print 3 digits, and fill in the deficiencies with 0

4.7 Specify Format Output


[deng@localhost ~]$ seq -f "str%03g" 9 11
str009
str010
str011
[deng@localhost ~]$ 

It means that the deficiency of printing 3 bits is filled with 0, and str is added in front of it

4.8 Add 0 before column so that width is the same


[deng@localhost ~]$ seq -w 9 11
09
10
11
[deng@localhost ~]$ 
 

Format strings should no longer be specified when outputting equal-width strings.-w and-f cannot be used at the same time

4.9 Separating Numbers with Specified Strings


 -f, --format= Format     Use printf  Floating-point format of style 
 -s, --separator= String      Separate numbers with the specified string ( Default uses: \n)
 -w, --equal-width    Add before the column 0  So that the width is the same 
   --help       Display this help and exit 
   --version      Display version information and exit 
0

4.10 Use the tab key to separate numbers


 -f, --format= Format     Use printf  Floating-point format of style 
 -s, --separator= String      Separate numbers with the specified string ( Default uses: \n)
 -w, --equal-width    Add before the column 0  So that the width is the same 
   --help       Display this help and exit 
   --version      Display version information and exit 
1

First make an tab with the command, and then specify it as a separator

05. Appendix

Reference: "Linux" 1-step 1-step Linux series tutorial summary


Related articles: