We can use regular expression matching like so: tmp]$ nl -b p"::" /etc/passwd Let's say we wanted to only number the lines for users with a UID and GUID of 0 through 2. Numbering Lines that Match a Regular Expression The syntax for adding one of the styles is: nl -b style filename Numbering All Lines ( a ) tmp]$ nl -ba testħ Maybe they will will be numbered, maybe not.Ĩ This is the end. I have yet to figure out why they included the ( n ) style which numbers no lines. p = Number only lines that contain a match for the basic regular expressionīy default the nl command uses the ( t ) style and numbers only nonempty lines.There are three output styles to choose from: The default style is right justified, no leading zeros, but it displays the same output as passing no style. ![]() Left Justified, No Leading Zeros ( ln ) tmp]$ nl -n ln /etc/passwd You can change the numbering format by using the -n option followed by your format of choice. The default numbering format is right justified, no leading zeros ( rn ). You can add a space after the colon (or any string) by using double quotes around a space like so: tmp]$ nl -s:" " /etc/passwdģ: daemon:x:2:2:daemon:/sbin:/sbin/nologinĥ: lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin You can use the -s option to add any string you want after the line number. For example, it would be common to see a colon after the number in a ordered list. There are many ways to format the output of the nl command. Here it took the /etc/passwd file and printed it to the screen with line numbers added to each line. tmp]$ nl /etc/passwdģ daemon:x:2:2:daemon:/sbin:/sbin/nologinĥ lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin The utility then takes the file and prints it to standard out and numbers each line. In the most basic usage of nl you pass a filename as an argument. Numbering Lines that Match a Regular Expressionīasic Usage Passing a Filename as an Argument.Left Justified, No Leading Zeros ( ln ).
0 Comments
Leave a Reply. |