Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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,
Cheers!

share|improve this question
add comment

1 Answer

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"?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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