Forrest logo
back to the nl tool

nl:tldr:6b4b1

nl: Number only the body lines that match a basic regular expression (BRE) pattern.
$ nl -b p'FooBar[0-9]' ${filename}
try on your machine

The command nl -b p'FooBar[0-9]' ${filename} is used to number the lines of a text file and display only the lines that contain the pattern "FooBar" followed by a digit (0-9). Here is a breakdown of each component of the command:

  • nl: This is the command itself, which stands for "number lines." It is used to display line numbers alongside the contents of a text file.

  • -b p: This is an option used with the nl command. It stands for "body numbering format" and specifies that only non-empty lines in the file should be numbered.

  • 'FooBar[0-9]': This is a regular expression pattern that is enclosed in single quotes. It specifies the pattern to match in each line of the file. In this case, it matches the string "FooBar" followed by any digit (0-9).

  • ${filename}: This is a placeholder for the actual name of the file on which the nl command will be executed. It is typically replaced with the name of the file or a variable containing the file name.

So, when this command is executed, it will number the lines of the specified file (${filename}) and only display the lines that contain the pattern "FooBar" followed by a digit.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the nl tool