Detailed explanation of the use of Linux seq command

Detailed explanation of the use of Linux seq command

01. Command Overview

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

02. Command format

usage:

 seq [options]... tailseq [options]... first number tailseq [options]... first number increment tailseq [options]...

03. Common options

Prints numbers starting from the first digit to the last digit in the specified increment.

 -f, --format=FORMAT Use printf-style floating point format -s, --separator=STRING Use the specified string to separate numbers (default: \n)
 -w, --equal-width Add 0 in front of columns to make them equal width --help Display this help message and exit --version Display version information and exit

04. Reference examples

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 Specifying the output format

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

It means -f specifies the format, % specifies 3 digits after it, the default is %g, and spaces are used to fill in the places where %3g does not have enough digits

4.6 Specifying output format

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

This means printing three digits and filling the missing digits with 0.

4.7 Specifying the output format

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

It means to print three missing digits with 0 and add str in front.

4.8 Add 0 in front of columns to make them have the same width

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

When outputting a fixed-width string, the format string should not be specified. -w and -f cannot be used together.

4.9 Use the specified string to separate numbers

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

4.10 Use the tab key to separate numbers

[deng@localhost ~]$ seq -s "`echo -e '\t'`" 9 11
9 10 11
[deng@localhost ~]$ 
 

First use the command to make a tab, and then specify it as a separator

05. Appendix

Reference: 【Linux】A summary of the series of tutorials on learning Linux step by step

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to use the Linux seq command
  • Use the Linux seq command to generate a sequence of numbers (recommended)

<<:  Django2.* + Mysql5.7 development environment integration tutorial diagram

>>:  Vue realizes the whole process of slider drag verification function

Recommend

Optimization analysis of Limit query in MySQL optimization techniques

Preface In actual business, paging is a common bu...

A brief introduction to MySQL functions

Table of contents 1. Mathematical functions 2. St...

Perfect solution for theme switching based on Css Variable (recommended)

When receiving this requirement, Baidu found many...

Three ways to jump to a page by clicking a button tag in HTML

Method 1: Using the onclick event <input type=...

mysql8.0.23 linux (centos7) installation complete and detailed tutorial

Table of contents What is a relational database? ...

Detailed usage of Vue timer

This article example shares the specific code of ...

How to add sudo permissions to a user in Linux environment

sudo configuration file The default configuration...

MySQL example of getting today and yesterday's 0:00 timestamp

As shown below: Yesterday: UNIX_TIMESTAMP(CAST(SY...

Nginx implements dynamic and static separation example explanation

In order to speed up the parsing of the website, ...

A brief discussion on JavaScript shallow copy and deep copy

Table of contents 1. Direct assignment 2. Shallow...

Ubuntu16.04 builds php5.6 web server environment

Ubuntu 16.04 installs the PHP7.0 environment by d...

Advantages of INSERT INTO SET in MySQL

Insert data into mysql database. Previously commo...

The perfect solution for Vue routing fallback (vue-route-manager)

Table of contents Routing Manager background gett...