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.

How to display line number while doing grep on a file. For example:

grep CONFIG_PM_ADVANCED_DEBUG /boot/config-`uname -r 
share|improve this question
add comment

4 Answers

up vote 15 down vote accepted

There is the option -n, and many more in the manual page, worth reading.

share|improve this answer
    
thanks ... i was going thru man grep. –  user7044 Aug 26 '11 at 12:16
add comment

grep -n <pattern> <file> prefixes each line of output with the line number in the input file. Is this what you are looking for?

share|improve this answer
    
mid-air collision with enzotib, who was faster –  Petr Uzel Aug 26 '11 at 12:20
add comment

alias grep='grep -inE --color=auto'

This will color the match as well for easy reading.

share|improve this answer
add comment

Have you checked cat -n 'filename'. This will print the line numbers.

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.