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

Implementation of CentOS8.0 network configuration

1. Differences in network configuration between C...

Detailed explanation of the benefits of PNG in various network image formats

BMP is an image file format that is independent o...

Example of using store in vue3 to record scroll position

Table of contents Overall Effect Listen for conta...

How to detect file system integrity based on AIDE in Linux

1. AIDE AIDE (Advanced Intrusion Detection Enviro...

MySQL merges multiple rows of data based on the group_concat() function

A very useful function group_concat(), the manual...

How to check where the metadata lock is blocked in MySQL

How to check where the metadata lock is blocked i...

Exploring the practical value of the CSS property *-gradient

Let me first introduce an interesting property - ...

Detailed description of the use of advanced configuration of Firewalld in Linux

IP masquerading and port forwarding Firewalld sup...

The 6 Most Effective Ways to Write HTML and CSS

This article shares the 6 most effective methods,...

Mysql uses insert to insert multiple records to add data in batches

If you want to insert 5 records into table1, the ...

Summary of the top ten problems of MySQL index failure

Table of contents background 1. The query conditi...

Solution to css3 transform transition jitter problem

transform: scale(); Scaling will cause jitter in ...