Home > other >  What does the nl -d actually do?
What does the nl -d actually do?

Time:01-09

i have to implement the nl command with arguments -s and -d in a shell made in C.My problem is that I don't understand what nl -d does.The man7 page says:-d, --section delimiter=CC /use CC for logical page delimiters but I don't get how to use it and what It does.I would appreciate some help.Thanks in advance.

CodePudding user response:

From IBM:

Uses the two characters specified by the Delimiter variable as the delimiters for the start of a logical page section. The default characters are \: (backslash, colon). You may specify two ASCII characters, two 1-byte extended characters, or one extended character. If you enter only one 1-byte character after the -d flag, the second character remains the default (a colon). If you want to use a backslash as a delimiter, enter two backslashes (\\).

CodePudding user response:

The delimiter is used to divide the input into sections - CCCCCC for a header, CCCC for a body section (The default when there are no dividers), CC for a footer.

From the POSIX description:

The nl utility views the text it reads in terms of logical pages. Line numbering shall be reset at the start of each logical page. A logical page consists of a header, a body, and a footer section. Empty sections are valid. Different line numbering options are independently available for header, body, and footer (for example, no numbering of header and footer lines while numbering blank lines only in the body).

Example input:

\:\:\:
the
header
\:\:
this
is
one
body
\:
a
footer
\:\:\:
another
header
\:\:
another
body
section
\:
another
footer

And output of running nl on it:


       the
       header

     1  this
     2  is
     3  one
     4  body

       a
       footer

       another
       header

     1  another
     2  body
     3  section

       another
       footer

With (GNU) nl's default options, only the body sections are numbered, and the count resets after each new header (Which starts a new logical page).

  •  Tags:  
  • Related