Mint

How to Print Line Number in Cat Command in Linux Mint 20.3

How_to_Print_Line_Number_in_Cat_Command_in_Linux_Mint_20.3

Introduction:

The cat command in Linux finds a very vast usage especially while dealing with files through the terminal. Apart from performing the read and write operations on the files, the cat command is also capable of displaying the line numbers with the file content. In this article, we will share with you the two methods of printing the line numbers in the cat command in Linux Mint 20.3.

Methods of Printing the Line Numbers in Cat Command in Linux Mint 20.3:

For printing the line numbers with the cat command in Linux Mint 20.3, you can use any of the following two methods:

Method # 1: Using the “-n” Flag with the Cat Command:

This method can be used to print line numbers with all the lines of a file regardless of whether it is an empty or a non-empty line. To do this, you just need to execute the command shown below:

$ cat –n sample.txt

Here, “sample.txt” is the name of our text file whose line numbers we want to print whereas “-n” is the flag that will be responsible for printing the line numbers in this case.

The line numbers along with all the lines of our specified file are shown in the following image:

Method # 2: Using the “-b” Flag with the Cat Command:

This method is used to print line numbers with all the non-empty lines of a specified file. To do this, you just need to execute the command shown below:

$ cat –b sample.txt

Here, “sample.txt” is the name of our text file whose line numbers we want to print whereas “-b” is the flag that will be responsible for printing the line numbers in this case.

The line numbers along with all the non-empty lines of our specified file are shown in the following image:

Conclusion:

This was a quick tutorial to teach you the different methods of printing the line numbers by using the cat command in Linux Mint 20.3. You can use either of these methods for printing the line numbers with the contents of your desired files in Linux Mint 20.3.

Similar Posts