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

js uses FileReader to read local files or blobs

Table of contents FileReader reads local files or...

Document Object Model (DOM) in JavaScript

Table of contents 1. What is DOM 2. Select elemen...

JavaScript plugin encapsulation for table switching

This article shares the encapsulation code of Jav...

Solution to the error reported by Mysql systemctl start mysqld

Error message: Job for mysqld.service failed beca...

Building a KVM virtualization platform on CentOS7 (three ways)

KVM stands for Kernel-based Virtual Machine, whic...

Detailed explanation of MySQL/Java server support for emoji and problem solving

This article describes the support and problem so...

Description of the default transaction isolation level of mysql and oracle

1. Transaction characteristics (ACID) (1) Atomici...

Detailed explanation of using JavaScript WeakMap

A WeakMap object is a collection of key/value pai...

About scroll bar in HTML/removing scroll bar

1. The color of the scroll bar under xhtml In the ...

Use docker to build kong cluster operation

It is very simple to build a kong cluster under t...

Solve the problem when setting the date to 0000-00-00 00:00:00 in MySQL 8.0.13

I just started learning database operations. Toda...

In-depth understanding of Linux load balancing LVS

Table of contents 1. LVS load balancing 2. Basic ...

JS realizes the automatic playback effect of pictures

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

Mysql aggregate function nested use operation

Purpose: Nested use of MySQL aggregate functions ...

How to use provide to implement state management in Vue3

Table of contents Preface How to implement Vuex f...