|
Filtering out SVN directories from grep outputPosted: Mar 24, 2009 Last modified: Apr 27, 2018I often need to use the tool grep to search for specific text under a directory tree in Linux. For example, I might want to search for every occurrence of the text "helper" in my latest web site source code. But when the source code is under Subversion, or SVN, version control, the results will be cluttered with more matches than you probably want. This is because of the text contained in the hidden .svn directories. Take, for example, the following grep command: $ grep -r "helper" .
./_edit_form.php:use_helper('MySite');
./.svn/text-base/_edit_form.php.svn-base:use_helper('MySite');
This searches for every occurrence of "helper" in the current directory and those below it (note the $ grep -r "helper" . | grep -v ".svn"
./_edit_form.php:use_helper('MySite');
It may seem to be of limited value when neither command yields many results, but it can be very useful when many matches appear in the SVN directories, sometimes causing the output of the command to take up more than one screen.
Of course, the principle can be applied to any other situation in which files containing a certain string (in this case ".svn") in their full path names need to be omitted from the results. |