<?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: sort problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331045#M189063</link>
    <description>cat file|sort -rnk3&lt;BR /&gt;&lt;BR /&gt;Gives, what you want&lt;BR /&gt;&lt;BR /&gt;Anil</description>
    <pubDate>Wed, 14 Jul 2004 07:28:38 GMT</pubDate>
    <dc:creator>RAC_1</dc:creator>
    <dc:date>2004-07-14T07:28:38Z</dc:date>
    <item>
      <title>sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331037#M189055</link>
      <description>vi test.txt&lt;BR /&gt;1   aaa   7&lt;BR /&gt;2   bbb   3&lt;BR /&gt;1   aaa   4&lt;BR /&gt;1   aaa   5&lt;BR /&gt;&lt;BR /&gt;When "sort a &amp;gt; b", the b would show&lt;BR /&gt;1   aaa   4&lt;BR /&gt;1   aaa   5&lt;BR /&gt;1   aaa   7&lt;BR /&gt;2   bbb   3&lt;BR /&gt;&lt;BR /&gt;But I want to get the result like below:&lt;BR /&gt;1   aaa   7&lt;BR /&gt;1   aaa   4&lt;BR /&gt;1   aaa   5&lt;BR /&gt;2   bbb   3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Because it is only search column1, and "1   aaa   7" is in the first line, but not "1   aaa  4" .  Does sort command can do that ? Thanks.</description>
      <pubDate>Wed, 14 Jul 2004 04:52:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331037#M189055</guid>
      <dc:creator>j773303</dc:creator>
      <dc:date>2004-07-14T04:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331038#M189056</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;not what you show because that is not sorted but read the man&lt;BR /&gt;&lt;BR /&gt;sort +2 -r /tmp/test.txt&lt;BR /&gt;1 aaa 7&lt;BR /&gt;1 aaa 5&lt;BR /&gt;1 aaa 4&lt;BR /&gt;2 bbb 3&lt;BR /&gt;&lt;BR /&gt;         Steve Steel</description>
      <pubDate>Wed, 14 Jul 2004 05:09:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331038#M189056</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2004-07-14T05:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331039#M189057</link>
      <description>I want the result as below:&lt;BR /&gt;1 aaa 7&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;2 bbb 3&lt;BR /&gt;&lt;BR /&gt;Becuase I select column 1 as the sort key.&lt;BR /&gt;See the source file,&lt;BR /&gt;1 aaa 7&lt;BR /&gt;2 bbb 3&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;&lt;BR /&gt;Since  &lt;BR /&gt;1 aaa 7  is the first line&lt;BR /&gt;1 aaa 4  is the third line&lt;BR /&gt;1 aaa 5  is the last line&lt;BR /&gt;&lt;BR /&gt;So, I want sort as below results:&lt;BR /&gt;1 aaa 7&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;2 bbb 3&lt;BR /&gt;&lt;BR /&gt;But sort will get the below results:&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;1 aaa 7&lt;BR /&gt;2 bbb 3&lt;BR /&gt;&lt;BR /&gt;It looks line it also sort the column 2 and column3.  From my point, I just want sort column1. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 14 Jul 2004 05:20:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331039#M189057</guid>
      <dc:creator>j773303</dc:creator>
      <dc:date>2004-07-14T05:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331040#M189058</link>
      <description># more file1&lt;BR /&gt;1 aaa 7&lt;BR /&gt;2 bbb 3&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;&lt;BR /&gt;The output.&lt;BR /&gt;# more file1 | sort +1&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;1 aaa 7&lt;BR /&gt;2 bbb 3&lt;BR /&gt;&lt;BR /&gt;This what i get but not 745 in the last col.&lt;BR /&gt;&lt;BR /&gt;Another way to add to it is:&lt;BR /&gt;# more file1 | sort +1 | sort +3 -r&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;1 aaa 7&lt;BR /&gt;2 bbb 3&lt;BR /&gt;&lt;BR /&gt;This is what i get but again no 745 in the last col.&lt;BR /&gt;&lt;BR /&gt;That's all.&lt;BR /&gt;Regards,</description>
      <pubDate>Wed, 14 Jul 2004 05:36:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331040#M189058</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2004-07-14T05:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331041#M189059</link>
      <description>Looks like sort(1) is not able to do what you want... according to the man page:&lt;BR /&gt; &lt;BR /&gt;---&lt;BR /&gt;Lines that otherwise compare equal are ordered with all bytes significant.  If all the specified keys compare equal, the entire record is used as the final key.&lt;BR /&gt;---&lt;BR /&gt; &lt;BR /&gt;Best regards...&lt;BR /&gt;Dietmar.</description>
      <pubDate>Wed, 14 Jul 2004 05:39:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331041#M189059</guid>
      <dc:creator>Dietmar Konermann</dc:creator>
      <dc:date>2004-07-14T05:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331042#M189060</link>
      <description>Hai,&lt;BR /&gt;&lt;BR /&gt; sort will try to check on key value first, If it is containing same vaules,it will go to next and so on.&lt;BR /&gt;&lt;BR /&gt;  1 aaa 7&lt;BR /&gt;  2 bbb 3&lt;BR /&gt;  1 aaa 4&lt;BR /&gt;  1 aaa 5&lt;BR /&gt; &lt;BR /&gt; cat test.file | sort -k 1&lt;BR /&gt; &lt;BR /&gt; There is no unique field in first key,so it is coming to second. Situation at 2 column is same. At last it is coming to 3rd one.&lt;BR /&gt;&lt;BR /&gt; Result will be as like that.&lt;BR /&gt;&lt;BR /&gt;  1 aaa 7&lt;BR /&gt;  2 bbb 3&lt;BR /&gt;  1 aaa 4&lt;BR /&gt;  1 aaa 3&lt;BR /&gt;&lt;BR /&gt;  It will give as,&lt;BR /&gt;  1 aaa 3&lt;BR /&gt;  1 aaa 4&lt;BR /&gt;  1 aaa 7&lt;BR /&gt;  2 bbb 3&lt;BR /&gt;&lt;BR /&gt;  It is sorting every column if there is no unique field to validate this,&lt;BR /&gt;&lt;BR /&gt;Change the input file as,&lt;BR /&gt;4 2 bbb 3&lt;BR /&gt;5 1 aaa 4&lt;BR /&gt;3 1 aaa 5&lt;BR /&gt;1 1 aaa 7&lt;BR /&gt;&lt;BR /&gt;cat test.file | sort -k 1&lt;BR /&gt;&lt;BR /&gt;1 1 aaa 7&lt;BR /&gt;3 1 aaa 5&lt;BR /&gt;4 2 bbb 3&lt;BR /&gt;5 1 aaa 4&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It is sorting only on first field only.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Muthukumar.  &lt;BR /&gt;</description>
      <pubDate>Wed, 14 Jul 2004 05:46:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331042#M189060</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-07-14T05:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331043#M189061</link>
      <description>Ugly workaround... prepend a line number, sort with line number a 2nd key and finally strip it off again. :)&lt;BR /&gt; &lt;BR /&gt; awk '{print NR, $0}' | sort -k 2,2 -k 1n,1n | cut -d ' ' -f 2-</description>
      <pubDate>Wed, 14 Jul 2004 05:50:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331043#M189061</guid>
      <dc:creator>Dietmar Konermann</dc:creator>
      <dc:date>2004-07-14T05:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331044#M189062</link>
      <description>Or:&lt;BR /&gt;tant # more a&lt;BR /&gt;1 aaa 7&lt;BR /&gt;2 bbb 3&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;tant # head -n1 a&amp;gt;c &amp;amp;&amp;amp; cat a|grep -v "`head -n1 a`"|sort&amp;gt;&amp;gt;c&lt;BR /&gt;tant # more c&lt;BR /&gt;1 aaa 7&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;2 bbb 3&lt;BR /&gt;&lt;BR /&gt;All the best&lt;BR /&gt;Victor</description>
      <pubDate>Wed, 14 Jul 2004 07:19:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331044#M189062</guid>
      <dc:creator>Victor BERRIDGE</dc:creator>
      <dc:date>2004-07-14T07:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331045#M189063</link>
      <description>cat file|sort -rnk3&lt;BR /&gt;&lt;BR /&gt;Gives, what you want&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Wed, 14 Jul 2004 07:28:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331045#M189063</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2004-07-14T07:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331046#M189064</link>
      <description>As you've seen, sort can't really do what you want, but there's always a solution &lt;BR /&gt;&lt;BR /&gt;for num in 1 2&lt;BR /&gt;do&lt;BR /&gt;grep "^$num " test.txt &amp;gt;&amp;gt; test2.txt&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;(note the space following $num in the quotes)&lt;BR /&gt;test2.txt then contains&lt;BR /&gt;&lt;BR /&gt;1 aaa 7&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;2 bbb 3</description>
      <pubDate>Wed, 14 Jul 2004 07:32:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331046#M189064</guid>
      <dc:creator>Chris Wilshaw</dc:creator>
      <dc:date>2004-07-14T07:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331047#M189065</link>
      <description>I'd also suggest you take a look at your point assignments;&lt;BR /&gt;&lt;BR /&gt;From your profile;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/publicProfile.do?userId=CA875590&amp;amp;forumId=1" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/publicProfile.do?userId=CA875590&amp;amp;forumId=1&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;You have assigned points to 426 of 1042  responses to your questions. &lt;BR /&gt;&lt;BR /&gt;That relates to a lot of assistance that you've received that you've not acknowledged.</description>
      <pubDate>Wed, 14 Jul 2004 07:34:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331047#M189065</guid>
      <dc:creator>Chris Wilshaw</dc:creator>
      <dc:date>2004-07-14T07:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331048#M189066</link>
      <description>&lt;BR /&gt;You want to take a file like this&lt;BR /&gt;1 aaa 7&lt;BR /&gt;2 bbb 3&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;&lt;BR /&gt;and put it into the form of this:&lt;BR /&gt;1 aaa 7&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;2 bbb 3&lt;BR /&gt;&lt;BR /&gt;Sorry, but that's not called sorting!&lt;BR /&gt;&lt;BR /&gt;It appears you are trying to move the records down based upon the first value. Thus I suggest you use something like awk:&lt;BR /&gt;&lt;BR /&gt;cat test.txt | awk 'BEGIN {system("rm newcraze.txt")} {print $0 &amp;gt; "craze"$1".tmp&lt;BR /&gt;";files[$1]="Y"} END {for(var=0;var&amp;lt;9;var++) {if (files[var] == "Y") {system("ca&lt;BR /&gt;t craze"var".tmp &amp;gt;&amp;gt;newcraze.txt");system("rm craze"var".tmp")}}}'&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Wed, 14 Jul 2004 08:02:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331048#M189066</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2004-07-14T08:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331049#M189067</link>
      <description>&lt;BR /&gt;Actually... on some systems this is called sorting, specifically 'stable' sorting.&lt;BR /&gt;IMHO, if one specifies explicit keys then a sort tool has no business to add in gratuitous extra keys (the whole record if equal). It could (IMHO) return records in random orders, or... when so requested in a STABLE order based on the input file order.&lt;BR /&gt;OpenVMS SORT (and SYNCSORT?) work that way. (See below).&lt;BR /&gt;Still, that does not matter because hpux sort is documented NOT to work that way.&lt;BR /&gt;&lt;BR /&gt;So here is a 'one-liner' workaround...&lt;BR /&gt;&lt;BR /&gt;awk '{printf ("%06d %s\n",NR,$0)}' x | sort -k 2,2 -k 3,3 -k 1,1 xx | cut -b 7-&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;OpenVMS example...&lt;BR /&gt;&lt;BR /&gt;$ typ tmp.tmp&lt;BR /&gt;1 aaa 7&lt;BR /&gt;2 bbb 3&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;$ sort/key=(pos:1,siz:5)/stable tmp.tmp sys$output:&lt;BR /&gt;1 aaa 7&lt;BR /&gt;1 aaa 4&lt;BR /&gt;1 aaa 5&lt;BR /&gt;2 bbb 3&lt;BR /&gt;</description>
      <pubDate>Wed, 14 Jul 2004 08:40:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331049#M189067</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-07-14T08:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331050#M189068</link>
      <description>Oops, I missed Dietmars earlier reply with the same/similar workaround of prepending a line number. (except that I opted for characters versus fields in the cut)&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 14 Jul 2004 08:50:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331050#M189068</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-07-14T08:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331051#M189069</link>
      <description>If you want the first 2 fields in ascending order and the third field descending, then what about the following-&lt;BR /&gt; &lt;BR /&gt;sort -k1,2 -k3r testfile&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 14 Jul 2004 08:58:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/3331051#M189069</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-07-14T08:58:09Z</dc:date>
    </item>
  </channel>
</rss>

