Print files with line numbers for each line in Linux
I was wondering if there is a way to print out files with line number printed as well. In Linux there is a very easy way – in fact several ways of accomplishing this. Here are a couple of them which easily lets you print line numbers alongside each line in your file.
cat -n FILE: Though not a part of the standard, most versions of
cathave an option,
-n, to print line numbers.
pr -n -t FILE: This is another method of printing line numbers in your files.
enscript -C: This is the third method.
nl FILE: But of all the above methods, this one takes the cake.
- In all the above cases, the output is printed on the screen. But if you want a post script output, then you can use the command
a2psas follows :
a2ps --line-numbers=1 FILE