{"id":77,"date":"2008-07-11T13:32:36","date_gmt":"2008-07-11T11:32:36","guid":{"rendered":"http:\/\/www.thomaskeller.biz\/blog\/?p=77"},"modified":"2008-07-11T13:33:16","modified_gmt":"2008-07-11T11:33:16","slug":"better-than-grep","status":"publish","type":"post","link":"https:\/\/www.thomaskeller.biz\/blog\/2008\/07\/11\/better-than-grep\/","title":{"rendered":"Better than grep"},"content":{"rendered":"<p>If you&#8217;re a programmer and you&#8217;re using a command line heavily, you&#8217;ve certainly come across a big nuisance in the usage of GNU&#8217;s <a href=\"http:\/\/man.cx\/grep(1)\/\">grep utility<\/a>: The verbosity you need to <em>exclude<\/em> files from being searched, such as backup files (*~ or *#) or any kind of vcs inventory stupidity like .svn or .cvs. (Did I mention earlier that this is one of the many reasons why I hate svn and cvs with a passion &#8211; for the fact that they clutter my workspace with this crap?)<\/p>\n<p>Anyways, with grep you usually end up with something like that:<\/p>\n<blockquote><p>$ grep -R myterm | grep -v &#8216;\\.svn&#8217; | grep -v &#8216;~:&#8217;<\/p><\/blockquote>\n<p>or, to speed up your searches a bit and let grep not even crawl things you don&#8217;t like to see anyways:<\/p>\n<blockquote><p>$ grep -R myterm `find . -type f | grep -v &#8216;\\.svn&#8217; | grep -v &#8216;~:&#8217;`<\/p><\/blockquote>\n<p>Anybody else thinks that this syntax is just hilarious and totally overkill? So I looked at grep&#8217;s manpage for some kind of .greprc which I could define in my homedir and in which I could set all the things I want to exclude, but apparently no such file is acknowledged by grep.<\/p>\n<p>Finally I did a Google search for <a href=\"http:\/\/google.com\/search?q=grep%20ignore%20svn%20directories\">&#8220;grep ignore svn directories&#8221;<\/a> and found <a href=\"http:\/\/petdance.com\/ack\/\"><em>ack<\/em><\/a> &#8211; a Perl tool which resolves this and other problems with grep. My personal feature highlights:<\/p>\n<ul>\n<li>You can use real Perl regular expressions (no grep -r stuff needed)<\/li>\n<li>-A, -B and -C options work just like I know them from grep<\/li>\n<li>Output is highlighted with terminal colors and very much cleaned up in comparison with grep<\/li>\n<li>There are predefined sets of file extensions to search, i.e. <code>ack --php foo<\/code> will search all php files (php3, php4, php, aso.) for foo, also with an option to exclude these sets with f.e <code>--noperl<\/code>\n<\/ul>\n<p>So I&#8217;m more than satisfied with this &#8211; if I would have only found this earlier! This saves my day!<\/p>\n<p>Oh, I think I forgot to mention one absolute killer feature of ack &#8211; to quote the author:<\/p>\n<blockquote><p>Command name is 25% fewer characters to type! Save days of free-time! Heck, it&#8217;s 50% shorter compared to grep -r.<\/p><\/blockquote>\n<p><a href=\"http:\/\/ack.googlecode.com\/svn\/tags\/latest\/ack-standalone\">Go, get it while its hot!<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re a programmer and you&#8217;re using a command line heavily, you&#8217;ve certainly come across a big nuisance in the usage of GNU&#8217;s grep utility: The verbosity you need to exclude files from being searched, such as backup files (*~ or *#) or any kind of vcs inventory stupidity like .svn or .cvs. (Did I &hellip; <a href=\"https:\/\/www.thomaskeller.biz\/blog\/2008\/07\/11\/better-than-grep\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Better than grep<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,13],"tags":[],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-coding","category-free-software"],"_links":{"self":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":1,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":341,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions\/341"}],"wp:attachment":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}