Please consider the following example:

$ grep --color=always -n 'Format\|Files' /usr/share/doc-base/doc-base | less -R

Here, grep will color also the line numbers of the matches, and less will display it.

I know I could show the entire file with line numbers in less with:

$ less -N /usr/share/doc-base/doc-base 

My question is - is there a way, to get less to display the entire file with line numbers - but where the line numbers are colored (as in the case with the grep output)?

Many thanks in advance for any answers,


Well, found something related to the above example - just have grep additionally match "start of line" (^), and all non-matching lines will pass "unharmed", with only the line numbers colored:

$ grep --color=always -n 'Format\|Files\|^' /usr/share/doc-base/doc-base | less -R

... (and as a bonus, matches stay highlighted).

However, I'd still like to know if less can be persuaded to do this "natively"?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.