{"id":1008,"date":"2014-11-03T13:23:30","date_gmt":"2014-11-03T20:23:30","guid":{"rendered":"http:\/\/jaredrobinson.com\/blog\/?p=1008"},"modified":"2014-11-03T13:23:30","modified_gmt":"2014-11-03T20:23:30","slug":"grepping-archived-rotated-log-files-in-order","status":"publish","type":"post","link":"https:\/\/jaredrobinson.com\/blog\/grepping-archived-rotated-log-files-in-order\/","title":{"rendered":"Grepping archived, rotated log files &#8212; in order"},"content":{"rendered":"<p>Say you&#8217;ve got the following log files with the oldest entries in myapi.log.3.gz:<\/p>\n<p>    myapi.log.1.gz<br \/>\n    myapi.log.2.gz<br \/>\n    myapi.log.3.gz<\/p>\n<p>If you want to &#8216;grep&#8217; them for a string, in order of date, oldest to newest, there&#8217;s no need to extract them one at a time, and there&#8217;s no need to concatenate the files first. Use sort to put the files in the proper order, and zgrep to search though the compressed files.<\/p>\n<p>Here&#8217;s how to order the file list:<\/p>\n<p>    ls myapi.log.*.gz | sort -nr -t . -k 3,3<\/p>\n<p>Here&#8217;s how to &#8216;zgrep&#8217; them in the proper order:<\/p>\n<p>    ls myapi.log.*.gz | sort -nr -t . -k 3,3 | xargs zgrep &#8220;404&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Say you&#8217;ve got the following log files with the oldest entries in myapi.log.3.gz: myapi.log.1.gz myapi.log.2.gz myapi.log.3.gz If you want to &#8216;grep&#8217; them for a string, in order of date, oldest to newest, there&#8217;s no need to extract them one at a time, and there&#8217;s no need to concatenate the files first. Use sort to put &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jaredrobinson.com\/blog\/grepping-archived-rotated-log-files-in-order\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Grepping archived, rotated log files &#8212; in order&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,17,30],"tags":[],"class_list":["post-1008","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming","category-tech","category-tools"],"_links":{"self":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/1008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/comments?post=1008"}],"version-history":[{"count":4,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/1008\/revisions"}],"predecessor-version":[{"id":1028,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/1008\/revisions\/1028"}],"wp:attachment":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/media?parent=1008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/categories?post=1008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/tags?post=1008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}