1f2155981SBrian Somers.\" 2f2155981SBrian Somers.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 3f2155981SBrian Somers.\" All rights reserved. 4f2155981SBrian Somers.\" 5f2155981SBrian Somers.\" This code is derived from software contributed to The NetBSD Foundation 6f2155981SBrian Somers.\" by Klaus Klein. 7f2155981SBrian Somers.\" 8f2155981SBrian Somers.\" Redistribution and use in source and binary forms, with or without 9f2155981SBrian Somers.\" modification, are permitted provided that the following conditions 10f2155981SBrian Somers.\" are met: 11f2155981SBrian Somers.\" 1. Redistributions of source code must retain the above copyright 12f2155981SBrian Somers.\" notice, this list of conditions and the following disclaimer. 13f2155981SBrian Somers.\" 2. Redistributions in binary form must reproduce the above copyright 14f2155981SBrian Somers.\" notice, this list of conditions and the following disclaimer in the 15f2155981SBrian Somers.\" documentation and/or other materials provided with the distribution. 16f2155981SBrian Somers.\" 17f2155981SBrian Somers.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18f2155981SBrian Somers.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19f2155981SBrian Somers.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20f2155981SBrian Somers.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21f2155981SBrian Somers.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22f2155981SBrian Somers.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23f2155981SBrian Somers.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24f2155981SBrian Somers.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25f2155981SBrian Somers.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26f2155981SBrian Somers.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27f2155981SBrian Somers.\" POSSIBILITY OF SUCH DAMAGE. 28f2155981SBrian Somers.\" 29*8a02ea1dSWarner Losh.Dd July 24, 2022 30f2155981SBrian Somers.Dt NL 1 31f2155981SBrian Somers.Os 32f2155981SBrian Somers.Sh NAME 337fa247d0SRuslan Ermilov.Nm nl 34f2155981SBrian Somers.Nd line numbering filter 35f2155981SBrian Somers.Sh SYNOPSIS 361e207e46SBrian Somers.Nm 37f2155981SBrian Somers.Op Fl p 38f2155981SBrian Somers.Bk -words 39f2155981SBrian Somers.Op Fl b Ar type 40f2155981SBrian Somers.Ek 41f2155981SBrian Somers.Bk -words 42f2155981SBrian Somers.Op Fl d Ar delim 43f2155981SBrian Somers.Ek 44f2155981SBrian Somers.Bk -words 45f2155981SBrian Somers.Op Fl f Ar type 46f2155981SBrian Somers.Ek 47f2155981SBrian Somers.Bk -words 48f2155981SBrian Somers.Op Fl h Ar type 49f2155981SBrian Somers.Ek 50f2155981SBrian Somers.Bk -words 51f2155981SBrian Somers.Op Fl i Ar incr 52f2155981SBrian Somers.Ek 53f2155981SBrian Somers.Bk -words 54f2155981SBrian Somers.Op Fl l Ar num 55f2155981SBrian Somers.Ek 56f2155981SBrian Somers.Bk -words 57f2155981SBrian Somers.Op Fl n Ar format 58f2155981SBrian Somers.Ek 59f2155981SBrian Somers.Bk -words 60f2155981SBrian Somers.Op Fl s Ar sep 61f2155981SBrian Somers.Ek 62f2155981SBrian Somers.Bk -words 63f2155981SBrian Somers.Op Fl v Ar startnum 64f2155981SBrian Somers.Ek 65f2155981SBrian Somers.Bk -words 66f2155981SBrian Somers.Op Fl w Ar width 67f2155981SBrian Somers.Ek 68f2155981SBrian Somers.Op Ar file 69f2155981SBrian Somers.Sh DESCRIPTION 70f2155981SBrian SomersThe 71f2155981SBrian Somers.Nm 72f2155981SBrian Somersutility reads lines from the named 73c401df01SSergey Kandaurov.Ar file , 74c401df01SSergey Kandaurovapplies a configurable line numbering filter operation, 75c401df01SSergey Kandaurovand writes the result to the standard output. 76c401df01SSergey KandaurovIf 77f2155981SBrian Somers.Ar file 78c401df01SSergey Kandaurovis a single dash 79c401df01SSergey Kandaurov.Pq Sq Fl 80c401df01SSergey Kandaurovor absent, 81c401df01SSergey Kandaurov.Nm 82c401df01SSergey Kandaurovreads from the standard input. 83f2155981SBrian Somers.Pp 84f2155981SBrian SomersThe 85f2155981SBrian Somers.Nm 86f2155981SBrian Somersutility treats the text it reads in terms of logical pages. 87f2155981SBrian SomersUnless specified otherwise, line numbering is reset at the start of each 886a3e8b0aSRuslan Ermilovlogical page. 896a3e8b0aSRuslan ErmilovA logical page consists of a header, a body and a footer 906a3e8b0aSRuslan Ermilovsection; empty sections are valid. 916a3e8b0aSRuslan ErmilovDifferent line numbering options are 92f2155981SBrian Somersindependently available for header, body and footer sections. 93f2155981SBrian Somers.Pp 94f2155981SBrian SomersThe starts of logical page sections are signalled by input lines containing 95f2155981SBrian Somersnothing but one of the following sequences of delimiter characters: 967fa247d0SRuslan Ermilov.Bl -column "\e:\e:\e:" "Start of" -offset indent 97f2155981SBrian Somers.Em "Line Start of" 9842dadc4aSRuslan Ermilov.It "\e:\e:\e: header" 9942dadc4aSRuslan Ermilov.It "\e:\e: body" 10042dadc4aSRuslan Ermilov.It "\e: footer" 101f2155981SBrian Somers.El 102f2155981SBrian Somers.Pp 103f2155981SBrian SomersIf the input does not contain any logical page section signalling directives, 104f2155981SBrian Somersthe text being read is assumed to consist of a single logical page body. 105f2155981SBrian Somers.Pp 106f2155981SBrian SomersThe following options are available: 107e8b02a42SRuslan Ermilov.Bl -tag -width ".Fl v Ar startnum" 108f2155981SBrian Somers.It Fl b Ar type 109f2155981SBrian SomersSpecify the logical page body lines to be numbered. 110f2155981SBrian SomersRecognized 111f2155981SBrian Somers.Ar type 112f2155981SBrian Somersarguments are: 1137fa247d0SRuslan Ermilov.Bl -tag -width indent 1147fa247d0SRuslan Ermilov.It Cm a 115f2155981SBrian SomersNumber all lines. 1167fa247d0SRuslan Ermilov.It Cm t 117f2155981SBrian SomersNumber only non-empty lines. 1187fa247d0SRuslan Ermilov.It Cm n 119f2155981SBrian SomersNo line numbering. 1207fa247d0SRuslan Ermilov.It Cm p Ns Ar expr 121f2155981SBrian SomersNumber only those lines that contain the basic regular expression specified 122f2155981SBrian Somersby 123f2155981SBrian Somers.Ar expr . 124f2155981SBrian Somers.El 125f2155981SBrian Somers.Pp 126f2155981SBrian SomersThe default 127f2155981SBrian Somers.Ar type 1287fa247d0SRuslan Ermilovfor logical page body lines is 1297fa247d0SRuslan Ermilov.Cm t . 130f2155981SBrian Somers.It Fl d Ar delim 131f2155981SBrian SomersSpecify the delimiter characters used to indicate the start of a logical 1326a3e8b0aSRuslan Ermilovpage section in the input file. 1336a3e8b0aSRuslan ErmilovAt most two characters may be specified; 134f2155981SBrian Somersif only one character is specified, the first character is replaced and the 135f2155981SBrian Somerssecond character remains unchanged. 136f2155981SBrian SomersThe default 137f2155981SBrian Somers.Ar delim 1387fa247d0SRuslan Ermilovcharacters are 1397fa247d0SRuslan Ermilov.Dq Li \e: . 140f2155981SBrian Somers.It Fl f Ar type 141f2155981SBrian SomersSpecify the same as 142f2155981SBrian Somers.Fl b Ar type 143f2155981SBrian Somersexcept for logical page footer lines. 144f2155981SBrian SomersThe default 145f2155981SBrian Somers.Ar type 1467fa247d0SRuslan Ermilovfor logical page footer lines is 1477fa247d0SRuslan Ermilov.Cm n . 148f2155981SBrian Somers.It Fl h Ar type 149f2155981SBrian SomersSpecify the same as 150f2155981SBrian Somers.Fl b Ar type 151f2155981SBrian Somersexcept for logical page header lines. 152f2155981SBrian SomersThe default 153f2155981SBrian Somers.Ar type 1547fa247d0SRuslan Ermilovfor logical page header lines is 1557fa247d0SRuslan Ermilov.Cm n . 156f2155981SBrian Somers.It Fl i Ar incr 157f2155981SBrian SomersSpecify the increment value used to number logical page lines. 158f2155981SBrian SomersThe default 159f2155981SBrian Somers.Ar incr 160f2155981SBrian Somersvalue is 1. 161f2155981SBrian Somers.It Fl l Ar num 162f2155981SBrian SomersIf numbering of all lines is specified for the current logical section 163f2155981SBrian Somersusing the corresponding 1647fa247d0SRuslan Ermilov.Fl b Cm a , 1657fa247d0SRuslan Ermilov.Fl f Cm a 166f2155981SBrian Somersor 1677fa247d0SRuslan Ermilov.Fl h Cm a 168f2155981SBrian Somersoption, 169f2155981SBrian Somersspecify the number of adjacent blank lines to be considered as one. 170f2155981SBrian SomersFor example, 171f2155981SBrian Somers.Fl l 172f2155981SBrian Somers2 results in only the second adjacent blank line being numbered. 173f2155981SBrian SomersThe default 174f2155981SBrian Somers.Ar num 175f2155981SBrian Somersvalue is 1. 176f2155981SBrian Somers.It Fl n Ar format 177f2155981SBrian SomersSpecify the line numbering output format. 178f2155981SBrian SomersRecognized 179f2155981SBrian Somers.Ar format 180f2155981SBrian Somersarguments are: 1817fa247d0SRuslan Ermilov.Bl -tag -width indent -compact 1827fa247d0SRuslan Ermilov.It Cm ln 183f2155981SBrian SomersLeft justified. 1847fa247d0SRuslan Ermilov.It Cm rn 185f2155981SBrian SomersRight justified, leading zeros suppressed. 1867fa247d0SRuslan Ermilov.It Cm rz 187f2155981SBrian SomersRight justified, leading zeros kept. 188f2155981SBrian Somers.El 189f2155981SBrian Somers.Pp 190f2155981SBrian SomersThe default 191f2155981SBrian Somers.Ar format 1927fa247d0SRuslan Ermilovis 1937fa247d0SRuslan Ermilov.Cm rn . 194f2155981SBrian Somers.It Fl p 195f2155981SBrian SomersSpecify that line numbering should not be restarted at logical page delimiters. 196f2155981SBrian Somers.It Fl s Ar sep 197f2155981SBrian SomersSpecify the characters used in separating the line number and the corresponding 198f2155981SBrian Somerstext line. 199f2155981SBrian SomersThe default 200f2155981SBrian Somers.Ar sep 201f2155981SBrian Somerssetting is a single tab character. 202f2155981SBrian Somers.It Fl v Ar startnum 203f2155981SBrian SomersSpecify the initial value used to number logical page lines; see also the 204f2155981SBrian Somersdescription of the 205f2155981SBrian Somers.Fl p 206f2155981SBrian Somersoption. 207f2155981SBrian SomersThe default 208f2155981SBrian Somers.Ar startnum 209f2155981SBrian Somersvalue is 1. 210f2155981SBrian Somers.It Fl w Ar width 211f2155981SBrian SomersSpecify the number of characters to be occupied by the line number; 212f2155981SBrian Somersin case the 213f2155981SBrian Somers.Ar width 214f2155981SBrian Somersis insufficient to hold the line number, it will be truncated to its 215f2155981SBrian Somers.Ar width 216f2155981SBrian Somersleast significant digits. 217f2155981SBrian SomersThe default 218f2155981SBrian Somers.Ar width 219f2155981SBrian Somersis 6. 220f2155981SBrian Somers.El 22133ec7f26STim J. Robbins.Sh ENVIRONMENT 22233ec7f26STim J. RobbinsThe 2234438d91eSRuslan Ermilov.Ev LANG , LC_ALL , LC_CTYPE 22433ec7f26STim J. Robbinsand 22533ec7f26STim J. Robbins.Ev LC_COLLATE 22633ec7f26STim J. Robbinsenvironment variables affect the execution of 22733ec7f26STim J. Robbins.Nm 22833ec7f26STim J. Robbinsas described in 22933ec7f26STim J. Robbins.Xr environ 7 . 230a866e170SRuslan Ermilov.Sh EXIT STATUS 231d628d776SRuslan Ermilov.Ex -std 23243ad0e15SFernando Apesteguía.Sh EXAMPLES 23343ad0e15SFernando ApesteguíaNumber all non-blank lines: 23443ad0e15SFernando Apesteguía.Bd -literal -offset indent 23543ad0e15SFernando Apesteguía$ echo -e "This is\\n\\n\\na simple text" | nl 23643ad0e15SFernando Apesteguía 1 This is 23743ad0e15SFernando Apesteguía 23843ad0e15SFernando Apesteguía 23943ad0e15SFernando Apesteguía 2 a simple text 24043ad0e15SFernando Apesteguía.Ed 24143ad0e15SFernando Apesteguía.Pp 24243ad0e15SFernando ApesteguíaNumber all lines including blank ones, with right justified line numbers with 24343ad0e15SFernando Apesteguíaleading zeroes, starting at 2, with increment of 2 and a custom multi-character 24443ad0e15SFernando Apesteguíaseparator: 24543ad0e15SFernando Apesteguía.Bd -literal -offset indent 24643ad0e15SFernando Apesteguía$ echo -e "This\\nis\\nan\\n\\n\\nexample" | nl -ba -n rz -i2 -s "->" -v2 24743ad0e15SFernando Apesteguía000002->This 24843ad0e15SFernando Apesteguía000004->is 24943ad0e15SFernando Apesteguía000006->an 25043ad0e15SFernando Apesteguía000008-> 25143ad0e15SFernando Apesteguía000010-> 25243ad0e15SFernando Apesteguía000012->example 25343ad0e15SFernando Apesteguía.Ed 25443ad0e15SFernando Apesteguía.Pp 25543ad0e15SFernando ApesteguíaNumber lines matching regular expression for an 25643ad0e15SFernando Apesteguía.Em i 25743ad0e15SFernando Apesteguía.No followed by either 25843ad0e15SFernando Apesteguía.Em m 25943ad0e15SFernando Apesteguía.No or 26043ad0e15SFernando Apesteguía.Em n 26143ad0e15SFernando Apesteguía.Bd -literal -offset indent 26243ad0e15SFernando Apesteguía$ echo -e "This is\\na simple text\\nwith multiple\\nlines" | nl -bp'i[mn]' 26343ad0e15SFernando Apesteguía This is 26443ad0e15SFernando Apesteguía 1 a simple text 26543ad0e15SFernando Apesteguía with multiple 26643ad0e15SFernando Apesteguía 2 lines 26743ad0e15SFernando Apesteguía.Ed 268f2155981SBrian Somers.Sh SEE ALSO 2693dbc6eb2SGarrett Wollman.Xr jot 1 , 270f2155981SBrian Somers.Xr pr 1 271f2155981SBrian Somers.Sh STANDARDS 272f2155981SBrian SomersThe 273f2155981SBrian Somers.Nm 274f2155981SBrian Somersutility conforms to 27566f9c15fSTim J. Robbins.St -p1003.1-2001 . 276f2155981SBrian Somers.Sh HISTORY 277f2155981SBrian SomersThe 278f2155981SBrian Somers.Nm 279f2155981SBrian Somersutility first appeared in 280*8a02ea1dSWarner Losh.At III . 281d99e9276STim J. Robbins.Sh BUGS 282d99e9276STim J. RobbinsInput lines are limited to 283d99e9276STim J. Robbins.Dv LINE_MAX 284d99e9276STim J. Robbins(2048) bytes in length. 285