Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of nl command in linux

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "the usage of nl command in linux". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Command format:

Nl [options]... [file].

2. Command parameters:

-b: there are two main ways to specify a line number:

-b a: indicates that the line number is also listed regardless of whether it is blank or not (similar to cat-n)

-b t: if there is a blank line, do not list the line number on the blank line (default)

-n: there are three main ways to list the line number representation:

-n ln: the line number is displayed on the far left side of the screen

-n rn: the line number is displayed on the rightmost side of your field without adding 0

-n rz: the line number is displayed on the rightmost side of your field, plus 0

-w: the number of digits occupied by the line number field.

-p does not restart the calculation at the logical delimiter.

3. Command function:

The nl command reads the File parameter (standard input by default), calculates the line number in the input, and writes the calculated line number to the standard output. In the output, the nl command calculates the left line based on the flag you specify on the command line. The input text must be written on the logical page. Each logical page has a header, body, and footer section (there can be an empty section). Unless you use the-p flag, the nl command resets the line number at the beginning of each logical page. Line calculation flags can be set separately for headers, bodies, and footer sections (for example, header and footer rows can be calculated but text lines cannot).

4. Use an example:

Example 1: list the contents of log2012.log with nl

Command:

Nl log2012.log

Output:

The code is as follows:

[root@localhost test] # nl log2012.log

1 2012-01

2 2012-02

3 = [root@localhost test] #

Description:

A blank line in the file, nl will not add a line number

Example 2: use nl to list the contents of log2012.log, and add line numbers to blank lines.

Command:

Nl-b a log2012.log

Output:

The code is as follows:

[root@localhost test] # nl-b a log2012.log

1 2012-01

2 2012-02

three

four

5 = [root@localhost test] #

Example 3: let the line number be automatically preceded by 0 to unify the output format

Command:

Output:

The code is as follows:

[root@localhost test] # nl-b a-n rz log2014.log

000001 2014-01

000002 2014-02

000003 2014-03

000004 2014-04

000005 2014-05

000006 2014-06

000007 2014-07

000008 2014-08

000009 2014-09

000010 2014-10

000011 2014-11

000012 2014-12

000013 =

[root@localhost test] # nl-b a-n rz-w 3 log2014.log

2014 01-01

2014-02

003 2014-03

2014-04

005 2014-05

006 2014-06

007 2014-07

008 2014-08

009 2014-09

010 2014-10

011 2014-11

012 2014-12

013 =

Description:

The nl-b a-n rz command line number defaults to six digits. To adjust the number of digits, you can add the parameter-w 3 to 3 digits.

This is the end of the introduction to "the use of nl commands in linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report