SyntaxHighlighter

Thursday, December 4, 2008

Grep and punctuation marks

I've often tried to use grep to filter search results for locate and several times I've had to search for a string with locate:
locate svn
This search would obviously include all the '.svn' folders too. Trying to get rid with them with
locate svn | grep -v '.svn'
does not work, since grep uses basic regular expressions, and the period mark will simply match any character.

To explicitly indicate the usage of a punctuation mark, one has to put it in brackets. The statement will now look something like:
locate svn | grep -v '[.]svn'

I just scanned through the grep man pages, and everything is explained pretty clearly there. I'd recommend reading the bit on regular expressions.

No comments: