Grep -- how do I ignore .svn directories?

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Grep -- how do I ignore .svn directories?

Post by alex.barylski »

Code: Select all

"grep -RnH '$what' $PROJECT_FIND_PATH "
I need the line numbers and such that grep offers (unless find does too?) the the results are expected in 'grep' format so find won't work unless it returns the results *exactly* the same...

I need to somehow ignore .svn directories -- possible?

Cheers,
Alex
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Grep -- how do I ignore .svn directories?

Post by VladSun »

As you know, you can always use find instead of grep -R ;)

Code: Select all

grep -nH $what `find '$where' -wholename '*/.svn*' -prune -o -print -type f`
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Grep -- how do I ignore .svn directories?

Post by alex.barylski »

Dude...your the man. 8)

Awesome...but I assume $where is project path?

Killer stuff...thanks again :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Grep -- how do I ignore .svn directories?

Post by Chris Corbyn »

I usually just do this:

Code: Select all

grep something /path | grep -v .svn
grep does have an --exclude=pattern option too.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Grep -- how do I ignore .svn directories?

Post by VladSun »

It's a too much resource consuming solution ;)
I mean - grep for a text is slower than pre-excluding directories not to be searched by using find.

And I'm not sure whether the --exclude=PATTERN option will match against full path string or file name string.
There are 10 types of people in this world, those who understand binary and those who don't
bottomless
Forum Newbie
Posts: 1
Joined: Wed Mar 31, 2010 7:40 pm

Re: Grep -- how do I ignore .svn directories?

Post by bottomless »

Use a recent version of grep (2.5.3 or better) so you can use the --exclude-dir switch that does work as expected:
http://blog.bottomlessinc.com/2008/06/i ... -searches/
Post Reply