Monday, March 26, 2018

Displaying lines numbers in Cat command

The syntax is:
cat -n fileName

OR
cat --number paul.txt

or  we cab use the more command/less command as filter when text can not be fitted on the screen:
cat --number foo.c | more
cat --number foo.c | less

The -b / --number-nonblank option number all nonempty output lines, starting with one and the syntax is:
cat -b fileName

OR
cat --number--nonblank filename

Finally, we can suppress or remove repeated empty output lines with the -s / --squeeze-blank option:
cat -s -n fileName
cat -s -n /etc/hosts




we can use the cat or nl command to display line numbers:

cat -n hello.c
nl hello.c



A note about sed
In the case just to print 7th and 9th line we can use the sed command:



sed -n -e 7p -e 9p /etc/resolv.conf

No comments: