Linux/Unix: Cat Command Display Line Numbers

You can display line numbers with the cat command by using the nl (number lines) command. Here’s an example:

nl [file_name]

Where [file_name] is the name of the file you want to display with line numbers. The nl command will print the contents of the file, with each line numbered.

If you want to display line numbers only for non-empty lines, you can use the following syntax:

nl -b a [file_name]

This will print the line numbers only for lines that contain characters, ignoring empty lines.

Leave a Comment