Hi all,
I am critically ri-considering my old posts, giving an answer (if I know!) in the hope to be of help to
some newbie (as I was some times ago).
To be sincere in many arguments I am still a newbie, but anyway...
About the item of line numbering, I have found that nl has all I need.
The default nl is right padding line numbering up to 6 characters and, besides that, it inserts
a tab between the number and the displayed line:
Quote:
000001 NL(1) User Commands NL(1)
000002
000003 NAME
000004 nl - number lines of files
000005
000006 SYNOPSIS
000007 nl [OPTION]... [FILE]...
000008
000009 DESCRIPTION
000010 Write each FILE to standard output, with line numbers added.
000011 With no FILE, or when FILE is -, read standard input.
000012
000013 Mandatory arguments to long options are mandatory for short options too.
000014
000015 -b, --body-numbering=STYLE
000016 use STYLE for numbering body lines
000017
000018 -d, --section-delimiter=CC
000019 use CC for separating logical pages
000020
000021 -f, --footer-numbering=STYLE
000022 use STYLE for numbering footer lines
000023
000024 -h, --header-numbering=STYLE
000025 use STYLE for numbering header lines
000026
000027 -i, --page-increment=NUMBER
000028 line number increment at each line
000029
000030 -l, --join-blank-lines=NUMBER
000031 group of NUMBER empty lines counted as one
000032
000033 -n, --number-format=FORMAT
000034 insert line numbers according to FORMAT
|
As you can see I have not used nl alone, but
Quote:
nl <file> -n rz -b a
where:
"-n rz" inserts line numbers according to format rz (right justified, leading zeros)
"-b a" numbers "all" lines (also the empty ones)
|
I quoted the "leading zeros" version, only to better show the effect of trimming.
Such trimming can be easily obtained by adding:
Quote:
-w <n>
For example, with "-w 3" 000034 --> 034
|
The last problem is the separator between line numbering and the line itself:
As a summary, the complete command for the line numbering
I wanted in my original post is:
Quote:
nl <file> -n rz -b a -w 3 -s " "
001 NL(1) User Commands NL(1)
002
003 NAME
004 nl - number lines of files
005
006 SYNOPSIS
007 nl [OPTION]... [FILE]...
008
009 DESCRIPTION
010 Write each FILE to standard output, with line numbers added.
011 With no FILE, or when FILE is -, read standard input.
012
013 Mandatory arguments to long options are mandatory for short options too.
014
015 -b, --body-numbering=STYLE
016 use STYLE for numbering body lines
017
018 -d, --section-delimiter=CC
019 use CC for separating logical pages
020
021 -f, --footer-numbering=STYLE
022 use STYLE for numbering footer lines
023
024 -h, --header-numbering=STYLE
025 use STYLE for numbering header lines
026
027 -i, --page-increment=NUMBER
028 line number increment at each line
029
030 -l, --join-blank-lines=NUMBER
031 group of NUMBER empty lines counted as one
032
033 -n, --number-format=FORMAT
034 insert line numbers according to FORMAT
|
Of course the padding depends on the number of lines of the file.
Bye.