Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

the fallowing grep

grep -r -e -n coll *

will display

fullpath/filename:  <tag-name>coll</tag-name>

I would like to know what line has the fallowing text, I tried adding -n, but it did not work. I tried adding | grep -n *, but it did something weird.

what I would like to see (I don't care about format)

fullpath/filename:10:  <tag-name>coll</tag-name>
share|improve this question
    
I see line numbers when using the -n option. Can you post the output of what you get? –  Kris Harper Nov 8 '11 at 15:58

2 Answers 2

up vote 11 down vote accepted

You should put -e at the end of the options list: grep -rne coll *

share|improve this answer

no need for -r & -e !

get line number of a pattern!

grep -n "pattern" file.txt

if you want to get only the line number as output add another grep command to it !

grep -n "pattern" file.txt | grep -Eo '^[^:]+'
share|improve this answer

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.