<?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 command in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974152#M783263</link>
    <description>Hi Srinivas,&lt;BR /&gt;sort -k1b,1 -k2.14nr,2.16 inputfile&lt;BR /&gt;run on my HPUX1i:&lt;BR /&gt;&lt;BR /&gt;10:12 GPOP09BN hpbbnn1/tmp/&amp;gt; cat f1&lt;BR /&gt;Akron C9.23.A1.City11 &lt;BR /&gt;Baltimore C8.90.C1.City4 &lt;BR /&gt;Chattanooga C51.9.A1.City5 &lt;BR /&gt;Akron C9.99.A1.City8 &lt;BR /&gt;Akron C9.21.A1.City9 &lt;BR /&gt;Baltimore C8.99.C1.City99 &lt;BR /&gt;Baltimore C8.99.C1.City1&lt;BR /&gt;Chattanooga C51.9.A1.City6 &lt;BR /&gt;&lt;BR /&gt;10:16 GPOP09BN hpbbnn1/tmp/&amp;gt; sort -k1b,1 -k2.14nr,2.16 f1&lt;BR /&gt;Akron C9.23.A1.City11 &lt;BR /&gt;Akron C9.21.A1.City9 &lt;BR /&gt;Akron C9.99.A1.City8 &lt;BR /&gt;Baltimore C8.99.C1.City99 &lt;BR /&gt;Baltimore C8.90.C1.City4 &lt;BR /&gt;Baltimore C8.99.C1.City1&lt;BR /&gt;Chattanooga C51.9.A1.City6 &lt;BR /&gt;Chattanooga C51.9.A1.City5 &lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
    <pubDate>Wed, 19 Apr 2006 03:17:20 GMT</pubDate>
    <dc:creator>Arturo Galbiati</dc:creator>
    <dc:date>2006-04-19T03:17:20Z</dc:date>
    <item>
      <title>sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974144#M783255</link>
      <description>Sort experts please help&lt;BR /&gt;I am trying to come up with a sort command that will sort the following input ...first on the 1st field in ascending order then the on 2nd field in numerically descending order based on the digits that follows the string "City"&lt;BR /&gt;&lt;BR /&gt;========Input===========&lt;BR /&gt;Akron C9.23.A1.City11 &lt;BR /&gt;Baltimore C8.90.C1.City4 &lt;BR /&gt;Chattanooga C51.9.A1.City5 &lt;BR /&gt;Akron C9.99.A1.City8 &lt;BR /&gt;Akron C9.21.A1.City9 &lt;BR /&gt;Baltimore C8.99.C1.City99 &lt;BR /&gt;Baltimore C8.99.C1.City1&lt;BR /&gt;Chattanooga C51.9.A1.City6  &lt;BR /&gt;&lt;BR /&gt;========Expected Output===========&lt;BR /&gt;Akron C9.23.A1.City11 &lt;BR /&gt;Akron C9.21.A1.City9 &lt;BR /&gt;Akron C9.99.A1.City8 &lt;BR /&gt;Baltimore C8.99.C1.City99 &lt;BR /&gt;Baltimore C8.90.C1.City4 &lt;BR /&gt;Baltimore C8.99.C1.City1&lt;BR /&gt;Chattanooga C51.9.A1.City6  &lt;BR /&gt;Chattanooga C51.9.A1.City5 &lt;BR /&gt;&lt;BR /&gt;Note: first the cities are sorted and then within the cities it is numerically sorted in descending order based on the digits that follow the string "City"&lt;BR /&gt;&lt;BR /&gt;Tried the following command and few more combinations nothing seems to be the solution for my requirements.&lt;BR /&gt;&lt;BR /&gt;sort -k1 -k2.14nr inputfile&lt;BR /&gt;&lt;BR /&gt;Salome to anyone who has spend their valuable time on this</description>
      <pubDate>Tue, 18 Apr 2006 10:40:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974144#M783255</guid>
      <dc:creator>Srinivas_9</dc:creator>
      <dc:date>2006-04-18T10:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974145#M783256</link>
      <description>Hi Srinivas, this is the most long and less efficient script I could elaborate :)&lt;BR /&gt;&lt;BR /&gt;for CITY in $(sort -uk1,1 tmp_input | awk '{print $1}')&lt;BR /&gt;do&lt;BR /&gt;  for NUM in $(awk -F'City' -vCITY=$CITY '$1 ~ CITY {print CITY, $2}' tmp_input | sort -n | awk '{print $2}')&lt;BR /&gt;  do&lt;BR /&gt;    echo "$(awk -F'City' -vNUM=$NUM -vCITY=$CITY '$1 ~ CITY &amp;amp;&amp;amp; $2 ~ NUM' tmp_input)"&lt;BR /&gt;  done&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;And this gives this:&lt;BR /&gt;&lt;BR /&gt;Akron C9.23.A1.City11&lt;BR /&gt;Akron C9.99.A1.City8&lt;BR /&gt;Akron C9.21.A1.City9&lt;BR /&gt;Baltimore C8.99.C1.City1&lt;BR /&gt;Baltimore C8.90.C1.City4&lt;BR /&gt;Baltimore C8.99.C1.City99&lt;BR /&gt;Chattanooga C51.9.A1.City5&lt;BR /&gt;Chattanooga C51.9.A1.City6&lt;BR /&gt;&lt;BR /&gt;So no perfect ordering since you have mixed one-two char numbers.&lt;BR /&gt;&lt;BR /&gt;It could be a starting point.&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Tue, 18 Apr 2006 11:14:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974145#M783256</guid>
      <dc:creator>Tiziano Contorno _</dc:creator>
      <dc:date>2006-04-18T11:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974146#M783257</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;first: it is always advisable to restrict the search, if multiple fields are involved.&lt;BR /&gt;However, this does not give your desired result as well:&lt;BR /&gt;sort -k1,1 -k2.14nr inputfile&lt;BR /&gt;&lt;BR /&gt;I have seen several times, that the sort-command had problems when dealing with numerical mode AND dots '.' in the string to be sorted.&lt;BR /&gt;Try this hack (you can use another 'interim char' as Â§ as long it is not part of your data). It works with Solaris8 (just no HP at hand).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;sed -e 's/ /Â§/' -e 's/City/&amp;amp;Â§/' inputfile | sort -tÂ§ -k1,1 -k3,3nr | sed -e 's/Â§/ /' -e 's/Â§//'&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Tue, 18 Apr 2006 11:22:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974146#M783257</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-04-18T11:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974147#M783258</link>
      <description>What if adjust the input file for sorting, then put it back-&lt;BR /&gt; &lt;BR /&gt;sed 's/City/City /' inputfile | sort -k1 -k3nr | sed 's/City /City/'&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 18 Apr 2006 11:26:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974147#M783258</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2006-04-18T11:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974148#M783259</link>
      <description>sort -k1b,1 -k2.14nr,2.16 inputfile&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Apr 2006 11:39:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974148#M783259</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2006-04-18T11:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974149#M783260</link>
      <description>My cut at this would be to use awk to extract the digits following city then sort it and finally reassemble it with awk.&lt;BR /&gt;&lt;BR /&gt;awk '{ split($2,x,"City"); print $1, x[2], $2 }' | sort -k 1,1 -k 2nr,2nr | awk '{print $1, $NF}' &amp;lt; infile &amp;gt; outfile</description>
      <pubDate>Tue, 18 Apr 2006 11:39:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974149#M783260</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-04-18T11:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974150#M783261</link>
      <description>Guys thanks a lot for the overwhelming response. As this is a minor requirement in a very complicated script, I will let u know which of the solutions offered below suits best for me.&lt;BR /&gt;&lt;BR /&gt;You guys are awesome.</description>
      <pubDate>Tue, 18 Apr 2006 15:00:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974150#M783261</guid>
      <dc:creator>Srinivas_9</dc:creator>
      <dc:date>2006-04-18T15:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974151#M783262</link>
      <description>Hi Srinivas,&lt;BR /&gt;&lt;BR /&gt;In your command sequence the "-k1" will try to sort from the first field to the end of the line...so your next "-k2.14nr" sort key will be ignored. You need to tell sort to restrict the first key "-k1,1" before moving onto the second sort key "-k2.14nr".&lt;BR /&gt;&lt;BR /&gt;# sort -k1,1 -k2.14nr inputfile&lt;BR /&gt;&lt;BR /&gt;cheers!</description>
      <pubDate>Tue, 18 Apr 2006 18:44:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974151#M783262</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-04-18T18:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974152#M783263</link>
      <description>Hi Srinivas,&lt;BR /&gt;sort -k1b,1 -k2.14nr,2.16 inputfile&lt;BR /&gt;run on my HPUX1i:&lt;BR /&gt;&lt;BR /&gt;10:12 GPOP09BN hpbbnn1/tmp/&amp;gt; cat f1&lt;BR /&gt;Akron C9.23.A1.City11 &lt;BR /&gt;Baltimore C8.90.C1.City4 &lt;BR /&gt;Chattanooga C51.9.A1.City5 &lt;BR /&gt;Akron C9.99.A1.City8 &lt;BR /&gt;Akron C9.21.A1.City9 &lt;BR /&gt;Baltimore C8.99.C1.City99 &lt;BR /&gt;Baltimore C8.99.C1.City1&lt;BR /&gt;Chattanooga C51.9.A1.City6 &lt;BR /&gt;&lt;BR /&gt;10:16 GPOP09BN hpbbnn1/tmp/&amp;gt; sort -k1b,1 -k2.14nr,2.16 f1&lt;BR /&gt;Akron C9.23.A1.City11 &lt;BR /&gt;Akron C9.21.A1.City9 &lt;BR /&gt;Akron C9.99.A1.City8 &lt;BR /&gt;Baltimore C8.99.C1.City99 &lt;BR /&gt;Baltimore C8.90.C1.City4 &lt;BR /&gt;Baltimore C8.99.C1.City1&lt;BR /&gt;Chattanooga C51.9.A1.City6 &lt;BR /&gt;Chattanooga C51.9.A1.City5 &lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
      <pubDate>Wed, 19 Apr 2006 03:17:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974152#M783263</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2006-04-19T03:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974153#M783264</link>
      <description>Guys thanks for the solutions provided.&lt;BR /&gt;Some worked some didnt.&lt;BR /&gt;&lt;BR /&gt;But I picked Rodney Hills solution for its simplicity and suited my needs exactly.&lt;BR /&gt;&lt;BR /&gt;LongLive HPForum.</description>
      <pubDate>Wed, 19 Apr 2006 20:53:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974153#M783264</guid>
      <dc:creator>Srinivas_9</dc:creator>
      <dc:date>2006-04-19T20:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: sort command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974154#M783265</link>
      <description>Closing thread.</description>
      <pubDate>Wed, 19 Apr 2006 20:56:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-command/m-p/4974154#M783265</guid>
      <dc:creator>Srinivas_9</dc:creator>
      <dc:date>2006-04-19T20:56:31Z</dc:date>
    </item>
  </channel>
</rss>

