<?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: numeric sort in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729260#M835928</link>
    <description>[root]pbctst: cat ttt | sort -n -k 1.6 -k 1.7,1.13 &lt;BR /&gt;ggggg-0000004-&lt;BR /&gt;eeeee-0000003-&lt;BR /&gt;fffff-0000002-&lt;BR /&gt;ggggg-0000001-&lt;BR /&gt;aaaaa+0000001+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;bbbbb+0000002+&lt;BR /&gt;ccccc+0000003+&lt;BR /&gt;ddddd+0000004+&lt;BR /&gt;&lt;BR /&gt;Sorts on the sign first, then the number. The -n option is probably freaking out on the fact that "+" and "-" aren't numbers.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
    <pubDate>Wed, 22 May 2002 14:24:28 GMT</pubDate>
    <dc:creator>harry d brown jr</dc:creator>
    <dc:date>2002-05-22T14:24:28Z</dc:date>
    <item>
      <title>numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729258#M835926</link>
      <description>I can't understand the behavior of the -n option from sort command. Consider a file with the following lines:&lt;BR /&gt;aaaaa+0000001+&lt;BR /&gt;bbbbb+0000002+&lt;BR /&gt;ccccc+0000003+&lt;BR /&gt;ddddd+0000004+&lt;BR /&gt;eeeee-0000003-&lt;BR /&gt;fffff-0000002-&lt;BR /&gt;ggggg-0000001-&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;ggggg-0000004-&lt;BR /&gt;&lt;BR /&gt;the command&lt;BR /&gt;sort -n -k 1.6,1.13&lt;BR /&gt;with the previous file produces:&lt;BR /&gt;ggggg-0000004-&lt;BR /&gt;eeeee-0000003-&lt;BR /&gt;fffff-0000002-&lt;BR /&gt;ggggg-0000001-&lt;BR /&gt;aaaaa+0000001+&lt;BR /&gt;bbbbb+0000002+&lt;BR /&gt;ccccc+0000003+&lt;BR /&gt;ddddd+0000004+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;&lt;BR /&gt;How come?&lt;BR /&gt;What about the two last lines of the output?&lt;BR /&gt;What I'm missing?&lt;BR /&gt;&lt;BR /&gt;gnu sort has the same behavior, but it has a -g option which behaves properly. Is there anything odd with -n option?&lt;BR /&gt;&lt;BR /&gt;(HP-UX noah B.11.00 U 9000/800 638329302 unlimited-user license)&lt;BR /&gt;</description>
      <pubDate>Wed, 22 May 2002 13:46:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729258#M835926</guid>
      <dc:creator>Miguel Covas</dc:creator>
      <dc:date>2002-05-22T13:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729259#M835927</link>
      <description>Hi Miguel:&lt;BR /&gt;&lt;BR /&gt;I think you want:&lt;BR /&gt;&lt;BR /&gt;# sort -n -k 1.6 -k 1.13 myfile&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 22 May 2002 14:17:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729259#M835927</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-05-22T14:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729260#M835928</link>
      <description>[root]pbctst: cat ttt | sort -n -k 1.6 -k 1.7,1.13 &lt;BR /&gt;ggggg-0000004-&lt;BR /&gt;eeeee-0000003-&lt;BR /&gt;fffff-0000002-&lt;BR /&gt;ggggg-0000001-&lt;BR /&gt;aaaaa+0000001+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;bbbbb+0000002+&lt;BR /&gt;ccccc+0000003+&lt;BR /&gt;ddddd+0000004+&lt;BR /&gt;&lt;BR /&gt;Sorts on the sign first, then the number. The -n option is probably freaking out on the fact that "+" and "-" aren't numbers.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Wed, 22 May 2002 14:24:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729260#M835928</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-05-22T14:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729261#M835929</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;dependant on what you need to do with the results you could do something like this strip out the - and + then sort works fine.If you need the plus and minus in the output this is not a lot of ggod.&lt;BR /&gt;&lt;BR /&gt;cat filename | tr "-" " " | tr "+" " " | sort -n +1&lt;BR /&gt;&lt;BR /&gt;John.</description>
      <pubDate>Wed, 22 May 2002 14:45:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729261#M835929</guid>
      <dc:creator>John Carr_2</dc:creator>
      <dc:date>2002-05-22T14:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729262#M835930</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;this will do it&lt;BR /&gt;&lt;BR /&gt;cat filename | tr "-" " - " | tr "+" " + " | sort -n +1 | tr " - " "-" | tr " + " "+"&lt;BR /&gt;&lt;BR /&gt;long winded but works.&lt;BR /&gt;&lt;BR /&gt;John.&lt;BR /&gt;</description>
      <pubDate>Wed, 22 May 2002 14:55:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729262#M835930</guid>
      <dc:creator>John Carr_2</dc:creator>
      <dc:date>2002-05-22T14:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729263#M835931</link>
      <description>after some further manual reading, plus some clues from previous replies I understand that sort -n does not consider a plus sign as the starting of a number (As, by the way, one can deduce from the manual). Only a minus or a blank can optionally start a number string sequence.&lt;BR /&gt;What drives to confusion is the fact that the manual states that +000.. will be treated as -000.. which implies the possible use of plus as starting sign.&lt;BR /&gt;&lt;BR /&gt;The proper solution seems to me replacing + with blank or zero.&lt;BR /&gt;&lt;BR /&gt;Thank you anywa</description>
      <pubDate>Wed, 22 May 2002 16:34:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729263#M835931</guid>
      <dc:creator>Miguel Covas</dc:creator>
      <dc:date>2002-05-22T16:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729264#M835932</link>
      <description>Hi Miguel:&lt;BR /&gt;&lt;BR /&gt;Ah, thank you.  In that case (using your input data):&lt;BR /&gt;&lt;BR /&gt;# sort -k 1.6r,1.6r -k 1.7n,1.13n -k 1.1,1.5 /tmp/sort&lt;BR /&gt;&lt;BR /&gt;...would yield:&lt;BR /&gt;&lt;BR /&gt;ggggg-0000001-&lt;BR /&gt;fffff-0000002-&lt;BR /&gt;eeeee-0000003-&lt;BR /&gt;ggggg-0000004-&lt;BR /&gt;aaaaa+0000001+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;ggggg+0000001+&lt;BR /&gt;bbbbb+0000002+&lt;BR /&gt;ccccc+0000003+&lt;BR /&gt;ddddd+0000004+&lt;BR /&gt;&lt;BR /&gt;BTW, I see that you joined the Forum today.  Welcome!!!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 22 May 2002 17:32:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729264#M835932</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-05-22T17:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729265#M835933</link>
      <description>Hi (again) Miguel:&lt;BR /&gt;&lt;BR /&gt;Oh, brain death. I keep looking at the sign on the right (after) the number *not* before, so disregard the last offering.&lt;BR /&gt;&lt;BR /&gt;The problem is nasty because the "-" sign appears higher (\055) in the collating sequence than the "+" sign {\053).  Worse yet, is that we want a descending numeric sort for negative numbers and an ascending one for positive ones.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 22 May 2002 17:51:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729265#M835933</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-05-22T17:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729266#M835934</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;yes I will get that result, which is not what is intended.&lt;BR /&gt;In numeric sorting negative number sort "descending" according to absolute value.&lt;BR /&gt;Positive numbers sort "ascending" according to absolute value. Managing absolute values as string is OK as long as you don't have decimal points.&lt;BR /&gt;&lt;BR /&gt;Mixing positive and negative values always needs numeric sorting with no tricks.</description>
      <pubDate>Wed, 22 May 2002 17:57:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729266#M835934</guid>
      <dc:creator>Miguel Covas</dc:creator>
      <dc:date>2002-05-22T17:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729267#M835935</link>
      <description>Hi  Miquel&lt;BR /&gt;&lt;BR /&gt;are the numbers posative and negative depending on plus or minus sign im sure we can still manipulate the file to give the right sequence ?&lt;BR /&gt;&lt;BR /&gt;John.</description>
      <pubDate>Wed, 22 May 2002 18:07:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729267#M835935</guid>
      <dc:creator>John Carr_2</dc:creator>
      <dc:date>2002-05-22T18:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729268#M835936</link>
      <description>The main problem I'm addressing is that most of these files come from environments where fixed length records are quite trendy. To adapt those files to unix-sort standards I need to substitute blank for plus sign at a given column, not every plus sign.&lt;BR /&gt;&lt;BR /&gt;This will do it while we look for a more elegant solution based on REs:&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;if (substr($0,6,1) == "+")&lt;BR /&gt;  print substr($0,1,5) " " substr($0,7) ;&lt;BR /&gt;else&lt;BR /&gt;  print $0 ;&lt;BR /&gt;}' | sort -k1.6n,1.13</description>
      <pubDate>Wed, 22 May 2002 18:39:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729268#M835936</guid>
      <dc:creator>Miguel Covas</dc:creator>
      <dc:date>2002-05-22T18:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729269#M835937</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;ok here we go again but you have to loose the plus signs and the trailing minus.&lt;BR /&gt;&lt;BR /&gt;cat filename | tr "+" " " | sed -e 's/-/ -/g' | awk '{ print $1 " " $2 }' | sort +n +1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;cheeers&lt;BR /&gt;&lt;BR /&gt;John.</description>
      <pubDate>Wed, 22 May 2002 18:51:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729269#M835937</guid>
      <dc:creator>John Carr_2</dc:creator>
      <dc:date>2002-05-22T18:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729270#M835938</link>
      <description>Hi Miquel&lt;BR /&gt;&lt;BR /&gt;I didn't see your last response before I submitted my last thoughts.&lt;BR /&gt;&lt;BR /&gt;good luck&lt;BR /&gt;John.</description>
      <pubDate>Wed, 22 May 2002 18:54:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729270#M835938</guid>
      <dc:creator>John Carr_2</dc:creator>
      <dc:date>2002-05-22T18:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: numeric sort</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729271#M835939</link>
      <description>Good try, but what about having more plus signs on different columns (For instance: 4.5e+08),&lt;BR /&gt;&lt;BR /&gt;and your awk will behave erratically if there are more blanks in the record.&lt;BR /&gt;&lt;BR /&gt;Please, don't take my example as the real files. It was intended just to example.&lt;BR /&gt;&lt;BR /&gt;Take&lt;BR /&gt;US3456357+0003.89-456A234&lt;BR /&gt;DE3562990-00233.3+4555666&lt;BR /&gt;DE34+++78+003.302N7888888&lt;BR /&gt;this col.^ to   ^&lt;BR /&gt;&lt;BR /&gt;First three plus signs of last record should not be lost&lt;BR /&gt;neither the last in the second record.&lt;BR /&gt;&lt;BR /&gt;BTW what about a nice ERE to substitute ONLY the sixth char.</description>
      <pubDate>Wed, 22 May 2002 19:02:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/numeric-sort/m-p/2729271#M835939</guid>
      <dc:creator>Miguel Covas</dc:creator>
      <dc:date>2002-05-22T19:02:55Z</dc:date>
    </item>
  </channel>
</rss>

