How to display line numbers in Terminal while displaying content of a file


In order to display the contents of a file in macOS/Linux/Unix Terminal you can make use of cat command - read more

Sample File:
Lorem ipsum dolor sit amet
ut mea nostrum detracto quaestio. 
Eu nobis denique fabellas est,
clita liberavisse duo an.
Nam vidit falli disputationi eu
usu nonumy nostro eirmod no.
Liber dictas incorrupte eum ex.
Qui illum singulis ei, 
duo te democritum disputationi, 
facer iisque aliquid ad eos.

In order to display the line numbers along with the text on the console we can make use of option -n along with the cat command and file name,

Example:
$ cat -n myfile.txt
     1	Lorem ipsum dolor sit amet
     2	ut mea nostrum detracto quaestio. 
     3	Eu nobis denique fabellas est,
     4	clita liberavisse duo an.
     5	Nam vidit falli disputationi eu
     6	usu nonumy nostro eirmod no.
     7	Liber dictas incorrupte eum ex.
     8	Qui illum singulis ei, 
     9	duo te democritum disputationi, 
    10	facer iisque aliquid ad eos.
Display line number in terminal for text file
Display line number in terminal for text file

Top Hashtags:

Advertisements

Advertisements




Advertisements