$linuxcli.in _    [commands]    [tips & tricks]    [manpage]    [ESXi CLi]    [what is my ip?]    [pingme!]    [BIOS lock code]    [Code repo]


View text file with line number


The cat command show the content of the text file and with the -n switch it provide content with line number.

Most of the time it is require to know at which line the character locate which we try to find and in some case this can be useful in bash scripting when try to automate the task to find the line number of certain character to add certain data after the search at specific line number or at same line number.

user@hostname$ cat -n foo.txt
1 Hello World
2 I am here
3 for the printf() output
4 echo also do the same
5

Last updated on 30 June 2023 10:43 am IST