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

Some common mistakes with MySQL null

According to null-values, the value of null in My...

A brief discussion on HTML ordered lists, unordered lists and definition lists

Ordered List XML/HTML CodeCopy content to clipboa...

Several ways to hide Html elements

1. Use CSS Copy code The code is as follows: style...

Why MySQL should avoid large transactions and how to solve them

What is a big deal? Transactions that run for a l...

How to create dynamic QML objects in JavaScript

1. Dynamically create objects There are two ways ...

CSS polar coordinates example code

Preface The project has requirements for charts, ...

js to achieve sliding carousel effect

This article shares the specific code of js to ac...

The pitfall record of case when judging NULL value in MySQL

Table of contents Preface Mysql case when syntax:...

32 Typical Column/Grid-Based Websites

If you’re looking for inspiration for columnar web...

Detailed explanation of data types in JavaScript basics

Table of contents 1. Data Type 1.1 Why do we need...

How to implement nested if method in nginx

Nginx does not support nested if statements, nor ...

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

When receiving this requirement, Baidu found many...

MySQL 8.0.23 free installation version configuration detailed tutorial

The first step is to download the free installati...