{"id":6401,"date":"2015-09-01T15:35:41","date_gmt":"2015-09-01T19:35:41","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=6401"},"modified":"2015-09-01T15:35:41","modified_gmt":"2015-09-01T19:35:41","slug":"grep-reading-apache-error-log-as-binary","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/","title":{"rendered":"Grep Reading Apache Error Log as Binary"},"content":{"rendered":"<p>An issue was recently noted where &#8216;<strong><em>grep<\/em><\/strong>&#8216; was throwing the error:<\/p>\n<p><code><br \/>\nroot@host [~]# zgrep \"ajax\" \/usr\/local\/apache\/logs\/error_log<br \/>\nBinary file (standard input) matches<br \/>\n<\/code><\/p>\n<p>The permissions were checked, and several other &#8216;<strong><em>grep<\/em><\/strong>&#8216; type commands were attempted and all returned the same error. In addition, the &#8216;<strong><em>head<\/em><\/strong>&#8216;, &#8216;<strong><em>tail<\/em><\/strong>&#8216; and &#8216;<strong><em>less<\/em><\/strong>&#8216; commands all returned the normal log information to standard output.<\/p>\n<p>In reviewing the issue, if there is a NUL character anywhere in the file, &#8216;<strong><em>grep<\/em><\/strong>&#8216; (or <strong><em>zgrep<\/em><\/strong>, <strong><em>egrep<\/em><\/strong>&#8230;etc.) will consider it as a binary file. <\/p>\n<p>To solve this, use the &#8216;<strong>-r<\/strong>&#8216; or <strong> &#8211; &#8211; text<\/strong> flags to process the binary file as if it were standard text; these flags are equivalent to the <strong>&#8211;binary-files=text<\/strong> option.<\/p>\n<p><code><br \/>\negrep -r -a mystring<br \/>\n<\/code><br \/>\nor<br \/>\n<code><br \/>\ngrep -a\/--text<\/code><\/p>\n<p>The downside to this is that the data returned may well result in binary information being sent to your terminal. This is not a good idea if you&#8217;re running a terminal such as VT\/DEC or many others that interprets the output stream. Alternatively, you can pipe\/output the file through &#8216;tr&#8217; with the following command:<br \/>\n<code><br \/>\ntr '[\\000-\\011\\013-\\037\\177-\\377]' '.' <test .log | grep whatever\n<\/code><br \/>\nwhich will change anything less than a space character (except newline) and anything greater than 126, into a . character, leaving only the printable characters.<\/p>\n<p>Nike!<\/test><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>An issue was recently noted where &#8216;grep&#8216; was throwing the error: root@host [~]# zgrep &#8220;ajax&#8221; \/usr\/local\/apache\/logs\/error_log Binary file (standard input) matches The permissions were checked, and several other &#8216;grep&#8216; type commands were attempted and all returned the same error. In addition, the &#8216;head&#8216;, &#8216;tail&#8216; and &#8216;less&#8216; commands all returned the normal log information to standard&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-6401","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Grep Reading Apache Error Log as Binary - Linux Shtuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Grep Reading Apache Error Log as Binary - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"An issue was recently noted where &#8216;grep&#8216; was throwing the error: root@host [~]# zgrep &quot;ajax&quot; \/usr\/local\/apache\/logs\/error_log Binary file (standard input) matches The permissions were checked, and several other &#8216;grep&#8216; type commands were attempted and all returned the same error. In addition, the &#8216;head&#8216;, &#8216;tail&#8216; and &#8216;less&#8216; commands all returned the normal log information to standard... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-01T19:35:41+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Grep Reading Apache Error Log as Binary\",\"datePublished\":\"2015-09-01T19:35:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/\"},\"wordCount\":192,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/\",\"name\":\"Grep Reading Apache Error Log as Binary - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2015-09-01T19:35:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/grep-reading-apache-error-log-as-binary\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Grep Reading Apache Error Log as Binary\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Grep Reading Apache Error Log as Binary - Linux Shtuff","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/","og_locale":"en_US","og_type":"article","og_title":"Grep Reading Apache Error Log as Binary - Linux Shtuff","og_description":"An issue was recently noted where &#8216;grep&#8216; was throwing the error: root@host [~]# zgrep \"ajax\" \/usr\/local\/apache\/logs\/error_log Binary file (standard input) matches The permissions were checked, and several other &#8216;grep&#8216; type commands were attempted and all returned the same error. In addition, the &#8216;head&#8216;, &#8216;tail&#8216; and &#8216;less&#8216; commands all returned the normal log information to standard... Read More","og_url":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2015-09-01T19:35:41+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Grep Reading Apache Error Log as Binary","datePublished":"2015-09-01T19:35:41+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/"},"wordCount":192,"commentCount":0,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/","url":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/","name":"Grep Reading Apache Error Log as Binary - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2015-09-01T19:35:41+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/grep-reading-apache-error-log-as-binary\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Grep Reading Apache Error Log as Binary"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/6401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=6401"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/6401\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=6401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=6401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=6401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}