{"id":457,"date":"2011-01-28T00:30:38","date_gmt":"2011-11-21T05:51:50","guid":{"rendered":"http:\/\/kraftek.com\/blog\/gawk-construct-to-build-a-line-from-each-3-lines\/"},"modified":"2014-06-04T22:19:44","modified_gmt":"2014-06-04T22:19:44","slug":"gawk-construct-to-build-a-line-from-each-3-lines","status":"publish","type":"post","link":"\/blog\/index.php\/gawk-construct-to-build-a-line-from-each-3-lines\/","title":{"rendered":"gawk construct to build a line from each 3 lines"},"content":{"rendered":"<p>We got the output from &#8220;sar -ruq&#8221; in a file, we stored in sar2.txt, and it looks like this:<\/p>\n<pre>\r\n11:44:51 633773 22954346\r\n4 1 3 93\r\n0.0 0 0.0 0\r\n11:44:56 633773 22954288\r\n2 2 1 94\r\n0.0 0 0.0 0\r\n11:45:01 632206 22786120\r\n13 18 13 56\r\n9.0 20 0.0 0\r\n11:45:06 625509 22462685\r\n53 47 0 0\r\n5.0 99 0.0 0\r\n<\/pre>\n<p>So we want to plot it in excel, we need one line per sample, much like this:<\/p>\n<pre>\r\n11:45:06 625509 22462685 53 47 0 0 5.0 99 0.0 0\r\n11:45:11 628749 22770298 59 41 0 0 4.8 100 0.0 0\r\n11:45:16 630432 22733837 55 45 0 0 6.8 100 0.0 0\r\n<\/pre>\n<p>So we wrote a small gawk expression to do it:<\/p>\n<pre>\r\ngawk 'ORS=NR%3?\" \":\"n\"' sar2.txt\r\n<\/pre>\n<p>So simple, we&#8217;re using the modulus function here to do the job. Coming to a blog near you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We got the output from &#8220;sar -ruq&#8221; in a file, we stored in sar2.txt, and it looks like this: 11:44:51 633773 22954346 4 1 3 93 0.0 0 0.0 0 11:44:56 633773 22954288 2 2 1 94 0.0 0 0.0 0 11:45:01 632206 22786120 13 18 13 56 9.0 20 0.0 0 11:45:06 625509 22462685 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":1,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":1073,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions\/1073"}],"wp:attachment":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}