14

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

grep CONFIG_PM_ADVANCED_DEBUG /boot/config-`uname -r 
32

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

6

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

  • mid-air collision with enzotib, who was faster – Petr Uzel Aug 26 '11 at 12:20
1

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

This will color the match as well for easy reading.

1

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

0
cat -n /boot/config | grep CONFIG_PM_ADVANCED_DEBUG

cat will -n[umber] the lines and | (filter) through grep looking only for lines with CONFIG_PM.... in them

the resulting output will be line number; the text of the line and the string

cat -n[umber lines] /Path/to/filename | grep -i[gnor case (optional)] STRING_TO_LOOK_FOR
  • Welcome to U&L. I edited your post, so it utilizes the formatting possibilities of the site a bit more. Please review the changes (with the edit history), so your future answers (and questions) might look better. It is also not necessary to "sign" your post, your name is posted with your profile on all answers – Anthon Oct 12 '15 at 7:33

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.