{"id":6201,"date":"2017-03-21T12:51:07","date_gmt":"2017-03-21T17:51:07","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=6201"},"modified":"2017-03-21T12:51:07","modified_gmt":"2017-03-21T17:51:07","slug":"awk-date-math","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2017\/03\/21\/awk-date-math\/","title":{"rendered":"awk date math"},"content":{"rendered":"<p>Just a reference post for how to determine the number of seconds between two date strings in awk.  If you have a normally formatted date string in Linux, such as &#8220;Sun Mar 19 00:50:33 EDT 2017&#8221;, you can convert this to a time object with the following&#8230;<\/p>\n<pre>\r\nbash-4.1$ grep 2017$ list2.out | awk 'BEGIN{split(\"Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec\",l,\"|\")} {for (i in l) {if ($2 == l[i]) {month=i}};split($4,t,\":\");t1=mktime($6\" \"month\" \"$3\" \"t[1]\" \"t[2]\" \"t[3]);if (last > 0 && t1-last > 35) {print $0,t1-last};last=t1}'\r\nSat Mar 18 17:14:18 EDT 2017 96\r\nSun Mar 19 00:50:33 EDT 2017 95\r\n<\/pre>\n<p>The mktime() command expects a date formatted as &#8220;year month day hour minute second&#8221;.  If you can parse that out of string, you can convert it to a date object and perform math operations on it.<\/p>\n<p>What is above prints only those lines that have a timestamp greater than 35 seconds after the previous sample.  It also prints the difference in seconds between the two samples.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just a reference post for how to determine the number of seconds between two date strings in awk. If you have a normally formatted date string in Linux, such as &#8220;Sun Mar 19 00:50:33 EDT 2017&#8221;, you can convert this&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2017\/03\/21\/awk-date-math\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[14,16],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6201"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6201"}],"version-history":[{"count":3,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6201\/revisions"}],"predecessor-version":[{"id":6204,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6201\/revisions\/6204"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6201"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}