<?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: sorting date in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055643#M736989</link>
    <description>I would do an awk to first take the first field mm/dd and split to determine if the month matches the current month. I would then print the month and day as separate fields followed by the rest of the line. Sort that output and finally use another awk to print fields 3-NF.&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset -i STAT=0&lt;BR /&gt;typeset MO=$(date '+%m') # current month&lt;BR /&gt;&lt;BR /&gt;awk -v month=${MO} \&lt;BR /&gt;'{ split($1,a,"/"); if ((a[1] + 0) == (month + 0)) {printf("%02d %02d ",a[1],a[2]); print $0; }}' | \&lt;BR /&gt;sort | \&lt;BR /&gt;awk '{for (i = 3; i &amp;lt;= (NF - 1); ++i) {printf("%s ",$i); print $NF}'&lt;BR /&gt;STAT=${?}&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;&lt;BR /&gt;The logic looks right and the syntax should be ok. The stuff abount (month + 0) is correct though it appears strange; it forces the evaluation into numerical context rather than string.&lt;BR /&gt;</description>
    <pubDate>Thu, 16 Aug 2007 14:30:12 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2007-08-16T14:30:12Z</dc:date>
    <item>
      <title>sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055640#M736986</link>
      <description>Does anyone know the sort syntax to sort the following output from the current month starting from the 1st down?&lt;BR /&gt;&lt;BR /&gt;07/23   testserver        /test/trees/oradb02    29%    &lt;BR /&gt;07/24   testserver        /test/trees/oradb02    29%    &lt;BR /&gt;07/25   testserver        /test/trees/oradb02    28%    &lt;BR /&gt;07/26   testserver        /test/trees/oradb02    29%    &lt;BR /&gt;07/27   testserver        /test/trees/oradb02    29%    &lt;BR /&gt;07/28   testserver        /test/trees/oradb02    29%    &lt;BR /&gt;07/29   testserver        /test/trees/oradb02    33%    &lt;BR /&gt;07/30   testserver        /test/trees/oradb02    29%    &lt;BR /&gt;07/31   testserver        /test/trees/oradb02    30%    &lt;BR /&gt;08/1    testserver        /test/trees/oradb02    30%    &lt;BR /&gt;08/2    testserver        /test/trees/oradb02    30%    &lt;BR /&gt;08/3    testserver        /test/trees/oradb02    32%    &lt;BR /&gt;08/4    testserver        /test/trees/oradb02    32%    &lt;BR /&gt;08/5    testserver        /test/trees/oradb02    36%    &lt;BR /&gt;08/6    testserver        /test/trees/oradb02    32%    &lt;BR /&gt;08/7    testserver        /test/trees/oradb02    36%    &lt;BR /&gt;08/8    testserver        /test/trees/oradb02    32%    &lt;BR /&gt;08/9    testserver        /test/trees/oradb02    37%    &lt;BR /&gt;08/10   testserver        /test/trees/oradb02    33%    &lt;BR /&gt;08/11   testserver        /test/trees/oradb02    33%    &lt;BR /&gt;08/12   testserver        /test/trees/oradb02    32%    &lt;BR /&gt;08/13   testserver        /test/trees/oradb02    31%    &lt;BR /&gt;08/14   testserver        /test/trees/oradb02    36%    &lt;BR /&gt;08/15   testserver        /test/trees/oradb02    36%    &lt;BR /&gt;08/16   testserver        /test/trees/oradb02    36%    &lt;BR /&gt;</description>
      <pubDate>Thu, 16 Aug 2007 13:23:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055640#M736986</guid>
      <dc:creator>hpuxrox</dc:creator>
      <dc:date>2007-08-16T13:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055641#M736987</link>
      <description>Please provide an example of how the output should look like. That would help in coming up with a viable solution.&lt;BR /&gt;&lt;BR /&gt;~cheers</description>
      <pubDate>Thu, 16 Aug 2007 14:01:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055641#M736987</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-08-16T14:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055642#M736988</link>
      <description>You can't sort that way.&lt;BR /&gt;&lt;BR /&gt;What you could do is grep the current month and then sort, then re-grep the previous and sort and append, etc...etc...&lt;BR /&gt;&lt;BR /&gt;grep ^`date +%m` somefile |sort -n&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Thu, 16 Aug 2007 14:19:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055642#M736988</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2007-08-16T14:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055643#M736989</link>
      <description>I would do an awk to first take the first field mm/dd and split to determine if the month matches the current month. I would then print the month and day as separate fields followed by the rest of the line. Sort that output and finally use another awk to print fields 3-NF.&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset -i STAT=0&lt;BR /&gt;typeset MO=$(date '+%m') # current month&lt;BR /&gt;&lt;BR /&gt;awk -v month=${MO} \&lt;BR /&gt;'{ split($1,a,"/"); if ((a[1] + 0) == (month + 0)) {printf("%02d %02d ",a[1],a[2]); print $0; }}' | \&lt;BR /&gt;sort | \&lt;BR /&gt;awk '{for (i = 3; i &amp;lt;= (NF - 1); ++i) {printf("%s ",$i); print $NF}'&lt;BR /&gt;STAT=${?}&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;&lt;BR /&gt;The logic looks right and the syntax should be ok. The stuff abount (month + 0) is correct though it appears strange; it forces the evaluation into numerical context rather than string.&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Aug 2007 14:30:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055643#M736989</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-08-16T14:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055644#M736990</link>
      <description>I suggest you do yourself a favor and first reformat the data, and then sort.&lt;BR /&gt;&lt;BR /&gt;Use SED or any tool you like. In perl I'd use:&lt;BR /&gt;&lt;BR /&gt;$perl -pe 's#/(\d\s)#/0${1}#' bad &amp;gt; good&lt;BR /&gt;or with in-place editing:&lt;BR /&gt;$ perl -i.old -pe 's#/(\d\s)#/0${1}#' mydata&lt;BR /&gt;&lt;BR /&gt;Of course you can sort with perl also. For example:&lt;BR /&gt;$ $ perl -ne '$data{$.}=$_;($m,$d)=split /[\/ ]/;$date{$.}=100*$m+$d}{foreach (sort {$date{$a}&amp;lt;=&amp;gt;$date{$b}} keys %date) {print $data{$_}}' y.txt&lt;BR /&gt;&lt;BR /&gt;or &lt;BR /&gt;&lt;BR /&gt;$ $ perl -e 'sub d {($m,$d)=split /[\/ ]/; return $m+100+$d} print sort {d($a)&amp;lt;=&amp;gt;d{$b}} &amp;lt;&amp;gt;' y.txt&lt;BR /&gt;&lt;BR /&gt;The first solution load two arrays indexed by a line number, one with each data line and one with the data recalculated to be month times 100 + day. The sort the date array by value and print.&lt;BR /&gt;&lt;BR /&gt;The next solution defines a function 'd' which gets that 100*M + D as return value for each record. Now print all input through a sort function comparing the 'd' function value for each input line.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Aug 2007 14:42:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055644#M736990</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-08-16T14:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055645#M736991</link>
      <description>Imho grep(1) and sort(1) ought to do it if I understand your requirement i.e. to extract and sort only those records that belong to the current month. If so you could try the command below:&lt;BR /&gt;&lt;BR /&gt;# grep $(date +%m) infile | sort -k1,1.2n -k1.4,1n</description>
      <pubDate>Thu, 16 Aug 2007 15:12:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055645#M736991</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-08-16T15:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055646#M736992</link>
      <description>In case it's not obvious, the script I supplied would read stdin and write on stdout.&lt;BR /&gt;&lt;BR /&gt;my.sh &amp;lt; infile &amp;gt; outfile&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Aug 2007 15:21:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055646#M736992</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-08-16T15:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055647#M736993</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Similar to Sandman's reply, you could leverage the "/" as a field delimiter and do:&lt;BR /&gt;&lt;BR /&gt;# sort -t/ -k1n -k2n file.in &amp;gt; file.out&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 16 Aug 2007 15:52:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055647#M736993</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-16T15:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: sorting date</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055648#M736994</link>
      <description>In case it's not obvious, I failed to correctly read the full request and jumped to answer a question not asked: sort all the data by date.&lt;BR /&gt;&lt;BR /&gt;I concur with Sandman! that it would be good to see suggested sample output. For example it's not clear to me that if say it is the second of the month, should the result be just 2 lines?&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Aug 2007 15:59:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-date/m-p/4055648#M736994</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-08-16T15:59:39Z</dc:date>
    </item>
  </channel>
</rss>

