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

Five practical tips for web form design

1. Mobile selection of form text input: In the te...

Implementing Markdown rendering in Vue single-page application

When rendering Markdown before, I used the previe...

How to use html table (to show the visual effect of web page)

We know that when using HTML on NetEase Blog, we ...

Proxy_pass method in multiple if in nginx location

1. First, let's review the relevant knowledge...

How to Rename a Group of Files at Once on Linux

In Linux, we usually use the mv command to rename...

Some parameter descriptions of text input boxes in web design

<br />In general guestbooks, forums and othe...

js array entries() Get iteration method

Table of contents 1. Detailed syntax of entires()...

Detailed example of creating and deleting tables in MySQL

The table creation command requires: The name of...

How to load Flash in HTML (2 implementation methods)

First method : CSS code: Copy code The code is as ...

A detailed introduction to for/of, for/in in JavaScript

Table of contents In JavaScript , there are sever...

The best solution for implementing digital plus and minus buttons with pure CSS

Preface: For the implementation of digital additi...

MySQL independent index and joint index selection

There is often a lack of understanding of multi-c...

JavaScript implements cool mouse tailing effects

After watching this, I guarantee that you have ha...

Detailed installation process of mysql5.7.21 under win10

This article shares the installation of MySQL 5.7...