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

Will Update in a Mysql transaction lock the table?

Two cases: 1. With index 2. Without index Prerequ...

The visual design path of the website should conform to user habits

Cooper talked about the user's visual path, w...

Solution to mysql error when modifying sql_mode

Table of contents A murder caused by ERR 1067 The...

Method of Vue component document generation tool library

Table of contents Parsing .vue files Extract docu...

Detailed explanation of HTML form elements (Part 1)

HTML forms are used to collect different types of...

Implementation of dynamic particle background plugin for Vue login page

Table of contents The dynamic particle effects ar...

Steps to create a CentOS container through Docker

Table of contents Preface Create a bridge network...

Implementation of CSS dynamic height transition animation effect

This question originated from a message on Nugget...

Detailed process of installing the docker plugin in IntelliJ IDEA (2018 version)

Table of contents 1. Development Environment 2. I...

Springboot+Vue-Cropper realizes the effect of avatar cutting and uploading

Use the Vue-Cropper component to upload avatars. ...

Example of CSS3 to achieve div sliding in and out from bottom to top

1. First, you need to use the target selector of ...