{"id":5003,"date":"2013-08-19T00:01:00","date_gmt":"2013-08-19T07:01:00","guid":{"rendered":"http:\/\/www.wambooli.com\/blog\/?p=5003"},"modified":"2013-08-17T12:23:41","modified_gmt":"2013-08-17T19:23:41","slug":"a-clutch-of-homebrew-unix-utilities","status":"publish","type":"post","link":"https:\/\/www.wambooli.com\/blog\/?p=5003","title":{"rendered":"A Clutch of Homebrew Unix Utilities"},"content":{"rendered":"<p>I just can&#8217;t stop programming! Ever since DOS, when I wrote handy utilities in BASIC (and then in Assembly and then in C), I want to code some handy little shortcut or interesting little problem-solver.<br \/>\n<!--more--><br \/>\nMy programming frenzy isn&#8217;t as necessary on the Mac. That&#8217;s because Unix has a clutch of handy utilities all ready to go. In fact, my goal now is to first scour the Unixverse to see whether or not the problem I have has already been solved. I don&#8217;t even want to get into all the various language tools available, <code>sed<\/code>, <code>awk<\/code>, <code>perl<\/code> &#8212; Unix is a rich environment.<\/p>\n<p>Even given the vast assortment of available utilities, I&#8217;ve felt the need to write my own. These programs dwell in my personal <code>bin<\/code> folder:<\/p>\n<p><strong>ascii.<\/strong> This program dumps out the ASCII code, columns of characters, decimal, and hex values. It saves me time from looking up the codes in the back of my books. It&#8217;s also reminiscent of the ASCII table that was once a part of the old Sidekick utility. Anyone remember that?<\/p>\n<p><strong>filename.<\/strong> This program swallows a filename as an argument, but removes the extension. Yes, I know that I could write a <code>sed<\/code> or <code>awk<\/code> script to do the same thing. Instead, I coded it in C. I forget why I needed to know the filename without the extension, but it was a high enough need that I coded my own utility.<\/p>\n<p><strong>gang.<\/strong> This is a full-screen file renaming utility that I wanted to write for a long time. As an author, I name documents with their chapter numbers, <code>01.doc<\/code> through <code>27.doc<\/code> or whatever. Occasionally I need to move things around, which requires massive file renaming duties. My <code>gang<\/code> utility lets me rename a gang of files all at once, in sequence. Screenshot shown in Figure 1.<\/p>\n<div id=\"attachment_5027\" style=\"width: 595px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5027\" src=\"http:\/\/www.wambooli.com\/blog\/wp-content\/uploads\/2013\/08\/TerminalScreenSnapz001.png\" alt=\"Figure 1. The &#039;gang&#039; program lets me rename\/renumber files en masse.\" width=\"585\" height=\"414\" class=\"size-full wp-image-5027\" srcset=\"https:\/\/www.wambooli.com\/blog\/wp-content\/uploads\/2013\/08\/TerminalScreenSnapz001.png 585w, https:\/\/www.wambooli.com\/blog\/wp-content\/uploads\/2013\/08\/TerminalScreenSnapz001-300x212.png 300w\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" \/><p id=\"caption-attachment-5027\" class=\"wp-caption-text\">Figure 1. The &#8216;gang&#8217; program lets me rename\/renumber files en masse.<\/p><\/div>\n<p><strong>hello.<\/strong> An amusing script. When I&#8217;m bored I often type <code>hello<\/code> at the prompt. This utility directs the Mac&#8217;s voice synthesizer to say, &#8220;Hello, Dan? Are you bored?&#8221;<\/p>\n<p><strong>icf.<\/strong> This program is a filter that takes standard input and capitalizes the first letter of every word. I have no idea why I wrote it.<\/p>\n<p><strong>lfname.<\/strong> This utility was born when I began transferring my writing archives to the Mac. It takes the ALL CAPS filenames generated from Windows and turns them into lower case. It&#8217;s essentially a gang-rename program: Run <code>lfname<\/code> in a directory and all the files are renamed to lower case.<\/p>\n<p><strong>mkdate.<\/strong> Perhaps my most favorite utility, <code>mkdate<\/code> generates a text string based on the current date. Without any arguments, the current date is produced, such as <code>20130819<\/code>. You can specify a formatting string as an argument to get the date output specifically (including month and weekday names), and include other text in the output as well. Two switches control the output: One suppresses the newline and the other prefixes any whitespace with a backslash.<\/p>\n<p>The reason I wrote <code>mkdate<\/code> is for archiving. I use it to create a folder named after the current date. I also use <code>mkdate<\/code> when building backup files. It&#8217;s pretty handy.<\/p>\n<p><strong>now.<\/strong> A copy of my old DOS utility, it spits out the current date and other trivial information. Here&#8217;s sample output:<\/p>\n<p><code>Today is Wednesday, August 21st 2013. It is the 233rd day of the year.<br \/>\nThe time is now 10:23:40 AM in the PDT timezone.<br \/>\nThe moon is waxing gibbous.<\/code><\/p>\n<p><strong>path.<\/strong> A perl script, this utility spits out the current search path.<\/p>\n<p><strong>reader.<\/strong> I wrote this full screen utility to view screenshot files I took for my old DOS books. I forget the name of the screen capture utility, but it was pretty easy to figure out how the text screen was stored. Below you see a sample from my book <em>Working With Magellan<\/em>, published in 1990.<\/p>\n<div id=\"attachment_5029\" style=\"width: 595px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5029\" src=\"http:\/\/www.wambooli.com\/blog\/wp-content\/uploads\/2013\/08\/TerminalScreenSnapz002.png\" alt=\"Figure 2. A rendering of the screen shot for Figure 6-1. Extended ASCII text appears using asterisks.\" width=\"585\" height=\"414\" class=\"size-full wp-image-5029\" srcset=\"https:\/\/www.wambooli.com\/blog\/wp-content\/uploads\/2013\/08\/TerminalScreenSnapz002.png 585w, https:\/\/www.wambooli.com\/blog\/wp-content\/uploads\/2013\/08\/TerminalScreenSnapz002-300x212.png 300w\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" \/><p id=\"caption-attachment-5029\" class=\"wp-caption-text\">Figure 2. A rendering of the screen shot for Figure 6-1. Extended ASCII text appears using asterisks.<\/p><\/div>\n<p><strong>skip.<\/strong> A filter that reads every <em>n<\/em>th line from standard input and sends it to standard output. Without an argument, every other line is skipped. Again, I have no idea why I wrote this.<\/p>\n<p><strong>width.<\/strong> My notes in the source code say that I needed this utility &#8220;today&#8221; and didn&#8217;t explain why. The program reads an entire text file. It outputs the widths of the longest line and the shortest line. I believe that the <code>awk<\/code> utility may be configured to perform that kind of magic, but I&#8217;m not good enough at <code>awk<\/code> to code it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just can&#8217;t stop programming! Ever since DOS, when I wrote handy utilities in BASIC (and then in Assembly and then in C), I want to code some handy little shortcut or interesting little problem-solver.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-5003","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5003"}],"version-history":[{"count":6,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5003\/revisions"}],"predecessor-version":[{"id":5040,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5003\/revisions\/5040"}],"wp:attachment":[{"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}