Predictive Hacks

How to display the line number in cat command

The cat command returns the content of the file and the nl command adds also the line number. For example:

cat myfile.txt
this is the first line
this is the second line
and this is the third
this should be the forth

Now, if we want to get the line number too, we can run:

nl myfile.txt
     1  this is the first line
     2  this is the second line
     3  and this is the third
     4  this should be the forth

Another option is to use the cat command with the -n option such as:

cat -n myfile.txt
     1  this is the first line
     2  this is the second line
     3  and this is the third
     4  this should be the forth

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.

Python

Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s