{"id":122,"date":"2012-07-17T13:31:07","date_gmt":"2012-07-17T13:31:07","guid":{"rendered":"http:\/\/vickistan.com\/?p=122"},"modified":"2015-12-29T15:39:41","modified_gmt":"2015-12-29T15:39:41","slug":"grepping-with-style","status":"publish","type":"post","link":"https:\/\/vickistan.com\/?p=122","title":{"rendered":"Grepping (and egrepping) with Style"},"content":{"rendered":"<p>Grep is a powerful tool. It can do many things well. It can also be used in conjunction with other tools. If you are new to grep, it is a supercharged search tool. The basic format of the command is:<\/p>\n<p>grep [options] PATTERN [FILE&#8230;]<\/p>\n<p>Many options are available and described in the man page, so I won&#8217;t go into them here. I will just list some of my favorite grep commands. (who am I kidding? I just want a place to copy them from when I am not at my own computer)<\/p>\n<p>#This command searches for a string and includes the preceding 5 lines and the 5 lines that follow it and shows the line numbers as well.<\/p>\n<p><code>grep -n -B5 -A5 searchstring \/tmp\/filename<\/code><\/p>\n<p>#This command uses grep to traverse the output from a find command.<br \/>\n<code>find . -exec grep searchstring {} \\; -print<\/code><\/p>\n<p>#This command allows you to output a sorted list of connections from the month of Mar 2013<br \/>\ngrep Mar\/2013 \/var\/log\/apache2\/access.log |\u00a0 awk &#8216;{ print $1 }&#8217; | sort -n | uniq -c | sort -rn | head<\/p>\n<p>#Finding warnings and errors in your log<br \/>\negrep -w &#8216;warning|error|critical&#8217; \/var\/log\/messages<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Grep is a powerful tool. It can do many things well. It can also be used in conjunction with other tools. If you are new to grep, it is a supercharged search tool. The basic format of the command is: &hellip; <a href=\"https:\/\/vickistan.com\/?p=122\">Continue reading <span class=\"meta-nav\">&rarr;<\/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],"tags":[],"class_list":["post-122","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=122"}],"version-history":[{"count":6,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":369,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions\/369"}],"wp:attachment":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}