How can I display line numbers using the cat command?

To display line numbers using the cat command, you can use the -n option. This option will number all output lines when displaying the contents of a file.

Example:

Here’s how to use it:

cat -n filename.txt

Explanation:

  • Replace filename.txt with the name of the file you want to display.
  • The -n option will prefix each line of the output with its corresponding line number.

Sample Output:

If filename.txt contains:

Hello, World!
This is a test file.
It has multiple lines.

The output with the -n option will look like this:

     1  Hello, World!
     2  This is a test file.
     3  It has multiple lines.

This makes it easy to reference specific lines in the file.

0 Comments

no data
Be the first to share your comment!