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

I want to search for javascript variables. So If my variable is geometry I want grep to return all lines like this e.g.

geometry.property1
myfunc(geometry)

etc..

but not these

geometryMark.property2

or

mygeometry.property3

So basically dont return instances where geometry is followed and/or preceded by a-z or A-Z characters

share|improve this question
add comment

1 Answer

You should be able to do that with the -w switch

-w, --word-regexp
          at  the  beginning  of  the  line,  or  preceded  by  a non-word
          of  the  line  or  followed by a non-word constituent character.

e.g. the matches for your examples are

$ grep -w 'geometry' myfile
geometry.property1
myfunc(geometry)

and the non-matches

$ grep -vw 'geometry' myfile
geometryMark.property2
mygeometry.property3
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.