How to use the Linux seq command

How to use the Linux seq command

1. Command Introduction

The seq (Sequence) command is used to generate all integers from the starting number to the ending number according to the specified step size. The default value 1 can be used for the start number and step size, but the end number must be specified.

2. Command format

seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST

3. Option Description

Note that mandatory arguments for long options are mandatory for short options as well.

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

4. Common Examples

(1) Output 1 to 5.

seq 5
# or seq 1 5
# or seq 1 1 5

(2) Generate a sequence of integers from 10 to 50 with a step size of 10.

seq 10 10 50
10
20
30
40
50

(3) Output in the specified format num%03g. num is the prefix string, %03g means the number width is 3, if it is less than 3, 0 will be added in front.

seq -f"num%03g" 3
num001
num002
num003

(4) Add leading zeros to make the numbers have the same width.

seq -w 9 11
09
10
11

Note that you cannot specify a format string when outputting a fixed-width string, that is, -w and -f cannot be used together.

(5) Use the specified string to separate numbers.

seq -w -s "," 9 11
09,10,11

(6) Use Tab to separate numbers.

seq -s "`echo -e '\t'`" 9 11
9 10 11

First use the command to create a Tab, and then specify it as a separator.

References
[1] seq(1) manual
[2]【Linux】Learn Linux step by step——seq command (221)

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:
  • Use the Linux seq command to generate a sequence of numbers (recommended)
  • Detailed explanation of the use of Linux seq command

<<:  Detailed explanation of MySQL database binlog cleanup command

>>:  In-depth understanding of React Native custom routing management

Recommend

Solve the problem of Docker starting Elasticsearch7.x and reporting an error

Using the Docker run command docker run -d -p 920...

MySQL 5.7.21 installation and configuration method graphic tutorial (window)

Install mysql5.7.21 in the window environment. Th...

vue-cli introduction and installation

Table of contents 1. Introduction 2. Introduction...

CentOS7.5 installation of MySQL8.0.19 tutorial detailed instructions

1. Introduction This article does not have screen...

How to monitor Linux server status

We deal with Linux servers every day, especially ...

JavaScript implements the nine-grid mobile puzzle game

This article shares the specific code for JavaScr...

How to elegantly implement the mobile login and registration module in vue3

Table of contents Preface Input box component lay...

MariaDB-server installation of MySQL series

Table of contents Tutorial Series 1. Install Mari...

How to configure VMware multi-node environment

This tutorial uses CentOS 7 64-bit. Allocate 2GB ...

How to construct a table index in MySQL

Table of contents Supports multiple types of filt...

Implementing image fragmentation loading function based on HTML code

Today we will implement a fragmented image loadin...

How to solve the problem of automatic package update in Debian system

I don't know when it started, but every time ...

How to configure Http, Https, WS, and WSS in Nginx

Written in front In today's Internet field, N...

JS Asynchronous Stack Tracing: Why await is better than Promise

Overview The fundamental difference between async...

Detailed explanation of how to enable slow query log in MySQL database

The database enables slow query logs Modify the c...