<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Replace leading zero with a space in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105492#M92510</link>
    <description>Note that this trick out-bushwhacks two things at once AND makes sure that your date is self-consistent.&lt;BR /&gt;&lt;BR /&gt;date '+%b %e %H' | read MON DAY HOUR&lt;BR /&gt;&lt;BR /&gt;The '%e' outputs the day with a possible leading space but the read strips off the whitespace IFS (Input Field Separator) so that the day is left as "1" rather than " 1".</description>
    <pubDate>Tue, 20 Nov 2007 10:39:39 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2007-11-20T10:39:39Z</dc:date>
    <item>
      <title>Replace leading zero with a space</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105486#M92504</link>
      <description>Here's a simple one but I'm having problems.  I want to format a date, for example "11/01/2007" as "Nov  1" (I want to space out the leading zero).  My script looks like this:&lt;BR /&gt;&lt;BR /&gt;MON=`date +%b`&lt;BR /&gt;DAY=`date +%d`&lt;BR /&gt;HOUR=`date +%H`&lt;BR /&gt; &lt;BR /&gt;EXT1=`echo ${MON} ${DAY} | tr "010203040506070809" " 1 2 3 4 5 6 7 8 9"`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This was working until today (Nov 20).  Instead of getting "Nov 20", I get "Nov 2 ".  I used the tr command to translate "Nov 01" to "Nov  1", etc.  I use this script to extract data from the syslog.log which is in this format.</description>
      <pubDate>Tue, 20 Nov 2007 10:07:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105486#M92504</guid>
      <dc:creator>Bob Ferro</dc:creator>
      <dc:date>2007-11-20T10:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Replace leading zero with a space</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105487#M92505</link>
      <description>If you look at your tr statement, the 0203 part.  02 and 20 are then matched.&lt;BR /&gt;&lt;BR /&gt;You will need to rework your matching.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Nov 2007 10:26:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105487#M92505</guid>
      <dc:creator>Tim Nelson</dc:creator>
      <dc:date>2007-11-20T10:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Replace leading zero with a space</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105488#M92506</link>
      <description>&lt;BR /&gt;Use %e rather than %d for the day of the month.&lt;BR /&gt;&lt;BR /&gt;Note that you should really do a single date command because you could execute this as 3 seprate commands and cross midnight so that you get a bogus date.&lt;BR /&gt;&lt;BR /&gt;date '+%b %e %H' | read MON DAY HOUR&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Nov 2007 10:27:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105488#M92506</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-11-20T10:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Replace leading zero with a space</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105489#M92507</link>
      <description>Hi Bob:&lt;BR /&gt;&lt;BR /&gt;Simply use:&lt;BR /&gt;&lt;BR /&gt;# DAY=`date +%e`&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 20 Nov 2007 10:27:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105489#M92507</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-11-20T10:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replace leading zero with a space</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105490#M92508</link>
      <description>If you don't want a leading zero or a space,&lt;BR /&gt;perhaps something like:&lt;BR /&gt;&lt;BR /&gt;DAY=` date +%d | sed -e 's/^0//' `&lt;BR /&gt;&lt;BR /&gt;or:&lt;BR /&gt;&lt;BR /&gt;DAY=` date +%e | sed -e 's/^ //' `&lt;BR /&gt;&lt;BR /&gt;"tr" looks like the wrong tool for this job.</description>
      <pubDate>Tue, 20 Nov 2007 10:33:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105490#M92508</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-11-20T10:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Replace leading zero with a space</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105491#M92509</link>
      <description>If the only purpose of ${MON} and ${DAY} is to serve as temporary variables for ${EXT1}, you should forgo their use and set ${EXT1} directly from the 'date' command:&lt;BR /&gt;&lt;BR /&gt;EXT1=$(date '+%b %e')&lt;BR /&gt;&lt;BR /&gt;PCS</description>
      <pubDate>Tue, 20 Nov 2007 10:36:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105491#M92509</guid>
      <dc:creator>spex</dc:creator>
      <dc:date>2007-11-20T10:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Replace leading zero with a space</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105492#M92510</link>
      <description>Note that this trick out-bushwhacks two things at once AND makes sure that your date is self-consistent.&lt;BR /&gt;&lt;BR /&gt;date '+%b %e %H' | read MON DAY HOUR&lt;BR /&gt;&lt;BR /&gt;The '%e' outputs the day with a possible leading space but the read strips off the whitespace IFS (Input Field Separator) so that the day is left as "1" rather than " 1".</description>
      <pubDate>Tue, 20 Nov 2007 10:39:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105492#M92510</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-11-20T10:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Replace leading zero with a space</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105493#M92511</link>
      <description>Any reason you want to do that?&lt;BR /&gt;To me it is better if all dates have the same number of character and don't special case any numbers.  After all, you don't want to be like some European locales that actually have a space or remove it and be shorter.</description>
      <pubDate>Wed, 21 Nov 2007 06:38:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-leading-zero-with-a-space/m-p/4105493#M92511</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-11-21T06:38:23Z</dc:date>
    </item>
  </channel>
</rss>

