How to use the Linux nl command

How to use the Linux nl command

1. Command Introduction

nl (Number of Lines) adds line numbers to the specified file and writes it to standard output. If no file is specified or the specified file is "-", the program will read data from standard input.

2. Usage

nl [options]... [file]...

3. Options

 : : : : : : : : : : : : : : : CC is the two delimiters used to separate logical page numbers. The missing second character implies ":". If you specify "\", 
Please enter "\\". The available styles are: 

 a Number all lines t Number non-blank lines n Do not number lines pBRE Number only lines that match the regular expression BRE FORMAT is one of the following: 

 ln Left-aligned, no spaces are filled with 0rn Right-aligned, no spaces are filled with 0rz Right-aligned, spaces are filled with 0

4. Examples

Example 1: Display line numbers

[root@oracledb study]# nl test1.log 
   1 2011
   2 2012
   3 2013

Example 2: Display line numbers and specify alignment

[root@oracledb study]# nl -nln test1.log 
1 2011
2 2012
3 2013
[root@oracledb study]# nl -nrn test1.log 
   1 2011
   2 2012
   3 2013
[root@oracledb study]# nl -nrz test1.log 
000001 2011
000002 2012
000003 2013

Example 3: Specify a width of 4 bits and the default is 6 bits

[root@oracledb study]# nl -nrz -w 4 test1.log 
0001 2011
0002 2012
0003 2013

Example 4: Number the contents of standard input

[root@oracledb study]# nl
line1
   1 line1
line2 
   2 line2
line3
   3 line3
[root@oracledb study]#

Press ctrl+D to end the input.

or EOF(End Of File)

[root@oracledb study]# nl <<EOF
> line1
> line2
> line3
> EOF
   1 line1
   2 line2
   3 line3

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:
  • Detailed explanation of Linux commands: how to use the useradd command
  • Detailed explanation of the usage of Linux top command
  • Usage of linux cut command
  • Detailed explanation of sudo command in Linux system
  • Detailed explanation of Linux shell command line options and parameters
  • Detailed analysis of the usage of the Linux mount command
  • How to use Linux tar compression and packaging command
  • Detailed usage of Linux ipcs command and ipcrm command
  • Detailed explanation of linux systemctl command
  • Detailed explanation of the use of rz command and sz command in Linux
  • Detailed explanation of Linux ls command parameters
  • Linux du command to view folder sizes and sort in descending order

<<:  Two methods of MySql comma concatenation string query

>>:  MySQL 8.0.17 decompression version installation and configuration method graphic tutorial

Recommend

Detailed use cases of vue3 teleport

Official Website https://cli.vuejs.org/en/guide/ ...

HTML table tag tutorial (46): table footer tag

The <tfoot> tag is used to define the style...

How to start a Vue.js project

Table of contents 1. Node.js and Vue 2. Run the f...

How to use Nginx to solve front-end cross-domain problems

Preface When developing static pages, such as Vue...

Sample code for nginx to achieve dynamic and static separation

1. Simple configuration of nginx's dynamic an...

Detailed Tutorial on Installing MySQL 5.7 on RedHat 6.5

RedHat6.5 installation MySQL5.7 tutorial sharing,...

Detailed explanation of process management in Linux system

Table of contents 1. The concept of process and t...

A brief analysis of MySQL locks and transactions

MySQL itself was developed based on the file syst...

Solution to the MySQL server has gone away error

MySQL server has gone away issue in PHP 1. Backgr...

Example of how to achieve ceiling effect using WeChat applet

Table of contents 1. Implementation 2. Problems 3...

Solution to the problem that Docker cannot stop or delete container services

Preface Today, a developer gave me feedback that ...

mysql 8.0.19 win10 quick installation tutorial

This tutorial shares the installation tutorial of...

Axios cancel request and avoid duplicate requests

Table of contents origin status quo Cancel reques...

mysql query data for today, this week, this month, and last month

today select * from table name where to_days(time...