{"id":7137,"date":"2019-01-04T05:27:25","date_gmt":"2019-01-04T05:27:25","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=7137"},"modified":"2019-01-08T11:35:12","modified_gmt":"2019-01-08T11:35:12","slug":"changing-the-month-format-a-fairly-general-solution","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/04\/changing-the-month-format-a-fairly-general-solution\/","title":{"rendered":"Changing the month format: a fairly general solution"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/img1\/banner.png\" alt=\"banner\" width=\"700\" height=\"140\" \/>For a full list of <em>BASHing data<\/em> blog posts, see the <a href=\"index.html\">index page<\/a>.<\/p>\n<p>I sometimes need to change the month format in a dataset, for instance from &#8220;Jan&#8221; to &#8220;01&#8221;, or &#8220;3&#8221; to &#8220;March&#8221;. There are various clever ways to do this on the command line, but I&#8217;m not good at remembering clever. To save time I wrote a table with the 6 different month formats I see most often. It&#8217;s the table you see below, and if you highlight and copy it, you should be able to paste it into a text editor as a tab-separated table. Save the file as &#8220;months&#8221;.<\/p>\n<table>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>01<\/td>\n<td>Jan<\/td>\n<td>January<\/td>\n<td>i<\/td>\n<td>I<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>02<\/td>\n<td>Feb<\/td>\n<td>February<\/td>\n<td>ii<\/td>\n<td>II<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>03<\/td>\n<td>Mar<\/td>\n<td>March<\/td>\n<td>iii<\/td>\n<td>III<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>04<\/td>\n<td>Apr<\/td>\n<td>April<\/td>\n<td>iv<\/td>\n<td>IV<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>05<\/td>\n<td>May<\/td>\n<td>May<\/td>\n<td>v<\/td>\n<td>V<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>06<\/td>\n<td>Jun<\/td>\n<td>June<\/td>\n<td>vi<\/td>\n<td>VI<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>07<\/td>\n<td>Jul<\/td>\n<td>July<\/td>\n<td>vii<\/td>\n<td>VII<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>08<\/td>\n<td>Aug<\/td>\n<td>August<\/td>\n<td>viii<\/td>\n<td>VIII<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>09<\/td>\n<td>Sep<\/td>\n<td>September<\/td>\n<td>ix<\/td>\n<td>IX<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>10<\/td>\n<td>Oct<\/td>\n<td>October<\/td>\n<td>x<\/td>\n<td>X<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td>11<\/td>\n<td>Nov<\/td>\n<td>November<\/td>\n<td>xi<\/td>\n<td>XI<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td>12<\/td>\n<td>Dec<\/td>\n<td>December<\/td>\n<td>xii<\/td>\n<td>XII<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>My general strategy is to use AWK to change formats, and to load &#8220;months&#8221; into an appropriate array in the AWK command. Below are a few examples.<\/p>\n<p>Expand abbreviated month<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/img3\/2018-12-30_1.png\" alt=\"first\" width=\"517\" height=\"222\" \/><\/p>\n<p>awk &#8216;FNR==NR \/-\/ &#8216; months file<\/p>\n<p>Split &#8220;full&#8221; date into ISO 8601 components<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/img3\/2018-12-30_2.png\" alt=\"second\" width=\"575\" height=\"288\" \/><\/p>\n<p>awk -F&#8221;t&#8221; &#8216;FNR==NR FNR==1 FNR&gt;1 &#8216; months file<\/p>\n<p>Convert &#8220;full American&#8221; date into Roman month-numeral date<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/img3\/2018-12-30_3.png\" alt=\"third\" width=\"520\" height=\"293\" \/><\/p>\n<p>awk -F&#8221;t&#8221; &#8216;FNR==NR FNR==1 FNR&gt;1 &#8216; months file<\/p>\n<p>Convert date range into ISO 8601 interval date<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/img3\/2018-12-30_4.png\" alt=\"fourth\" width=\"650\" height=\"262\" \/><\/p>\n<p>awk &#8216;FNR==NR \/[0-9]-[0-9]\/ \/ &#8211; \/ &amp;&amp; length($0)&lt;21 \/ &#8211; \/ &amp;&amp; length($0)&gt;21 &#8216; months file<\/p>\n<p>To remind myself which fields are which in &#8220;months&#8221;, I just cat the file before building the AWK command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/img3\/2018-12-30_5.png\" alt=\"months\" width=\"509\" height=\"263\" \/><\/p>\n<p>Last update: 2018-12-30<\/p>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=264390\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For a full list of BASHing data blog posts, see the index page. I sometimes need to change the month format in a dataset, for instance from &#8220;Jan&#8221; to &#8220;01&#8221;, or &#8220;3&#8221; to &#8220;March&#8221;. There are various clever ways to do this on the command line, but I&#8217;m not good at remembering clever. To save &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/04\/changing-the-month-format-a-fairly-general-solution\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Changing the month format: a fairly general solution&#8221;<\/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":[1],"tags":[],"class_list":["post-7137","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=7137"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7137\/revisions"}],"predecessor-version":[{"id":7457,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7137\/revisions\/7457"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=7137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=7137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=7137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}