{"id":1521,"date":"2013-01-22T12:58:04","date_gmt":"2013-01-22T12:58:04","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=1521"},"modified":"2013-01-22T12:58:04","modified_gmt":"2013-01-22T12:58:04","slug":"trick-grep-not-to-report-itself-in-a-process-search","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=1521","title":{"rendered":"Trick grep not to report itself in a process search"},"content":{"rendered":"<p>How often have you searched for a process, using ps and grep?<\/p>\n<div>\n<pre>$ ps -ef |grep emacs\r\npeter     7107     1  1 09:10 ?        00:00:08 \/usr\/bin\/emacs-snapshot-gtk\r\npeter     7377  7050  0 09:19 pts\/0    00:00:00 grep emacs<\/pre>\n<p>It always reports one more process than you want to see &#8230; namely the grep process itself.<\/p>\n<p>In the example above, the process 7377 is the grep process itself. What you really want is the 7107 emacs process.<\/p>\n<p>While this is really harmless (albeit annoying), it can be a real pain if you put this in a script. In that case, you have to parse out the grep process itself.<\/p>\n<p>You can trick grep not to report itself by enclosing a character in the search string in square brackets:<\/p>\n<pre>$ ps -ef |grep emac[s]\r\npeter     7107     1  1 09:10 ?        00:00:10 \/usr\/bin\/emacs-snapshot-gtk<\/pre>\n<p>Square brackets in bash are character matching patterns. emac[s] will only match the string\u00a0emacs.<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>How often have you searched for a process, using ps and grep? $ ps -ef |grep emacs peter 7107 1 1 09:10 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1521","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1521"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1521\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}