<?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 problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548625#M875581</link>
    <description>Uhmm, &lt;BR /&gt;&lt;BR /&gt;let's give this a try:&lt;BR /&gt;&lt;BR /&gt;cat your_file | sort -t, -n +1 -2 | awk -F, 'BEGIN {prev="" } {if (prev!=$2) {print $0; prev=$2} else {prev=$2}}' -&lt;BR /&gt;&lt;BR /&gt;About the double sort: this should work to a certain extent with a double range declaration. But I'm not sure if the second sort really does a dictionary sort or converts the chars to an ascii value and sorts them numerically.&lt;BR /&gt;&lt;BR /&gt;E.g.:&lt;BR /&gt;&lt;BR /&gt;cat your_file | sort -t, -n +1 -2 -d +4 -5&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Vincent</description>
    <pubDate>Wed, 04 Jul 2001 05:36:28 GMT</pubDate>
    <dc:creator>Vincent Stedema</dc:creator>
    <dc:date>2001-07-04T05:36:28Z</dc:date>
    <item>
      <title>Sorting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548622#M875578</link>
      <description>Dear all&lt;BR /&gt;&lt;BR /&gt;I would like to ask a question on 'sort' in Unix.&lt;BR /&gt;&lt;BR /&gt;I have a file which contains the following records:&lt;BR /&gt;&lt;BR /&gt;18,0001,abc,xyz&lt;BR /&gt;19,0001,wxy,ghi&lt;BR /&gt;&lt;BR /&gt;I would like to sort by the second field in the record. If more than one records are found with the same second field, then I only want the first record. That is to say, in the example above, I only want to return&lt;BR /&gt;18,0001,abc,xyz&lt;BR /&gt;&lt;BR /&gt;Another question,&lt;BR /&gt;How do I sort using more than one fields in the record, for example&lt;BR /&gt;20,123,abc,def&lt;BR /&gt;21,246,xyz,ijk&lt;BR /&gt;I would like to sort by the second and last field. How do I do do that using the 'sort' command?&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Jul 2001 05:03:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548622#M875578</guid>
      <dc:creator>Marko_3</dc:creator>
      <dc:date>2001-07-04T05:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548623#M875579</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Try&lt;BR /&gt;&lt;BR /&gt;sort  -u  -t,  -k2,2  file_to_be_sorted&lt;BR /&gt;&lt;BR /&gt;Rgds</description>
      <pubDate>Wed, 04 Jul 2001 05:17:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548623#M875579</guid>
      <dc:creator>Wieslaw Krajewski</dc:creator>
      <dc:date>2001-07-04T05:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548624#M875580</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;This script will sort out your 'filename' in terms of 2nd field and keep it in newfile. It will keep only the first line of similar content as you required....&lt;BR /&gt;&lt;BR /&gt;cat filename | awk'FS = "," {print $2}' | sort -n &amp;gt; tempfile&lt;BR /&gt;for i in 'tmpfile'&lt;BR /&gt;do&lt;BR /&gt;grep $i filename | head -1 &amp;gt;&amp;gt; newfile&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regarding sort in 2 fields, you have to write similar kind of script......&lt;BR /&gt;&lt;BR /&gt;Hope it helps.....</description>
      <pubDate>Wed, 04 Jul 2001 05:31:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548624#M875580</guid>
      <dc:creator>vtpaulson</dc:creator>
      <dc:date>2001-07-04T05:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548625#M875581</link>
      <description>Uhmm, &lt;BR /&gt;&lt;BR /&gt;let's give this a try:&lt;BR /&gt;&lt;BR /&gt;cat your_file | sort -t, -n +1 -2 | awk -F, 'BEGIN {prev="" } {if (prev!=$2) {print $0; prev=$2} else {prev=$2}}' -&lt;BR /&gt;&lt;BR /&gt;About the double sort: this should work to a certain extent with a double range declaration. But I'm not sure if the second sort really does a dictionary sort or converts the chars to an ascii value and sorts them numerically.&lt;BR /&gt;&lt;BR /&gt;E.g.:&lt;BR /&gt;&lt;BR /&gt;cat your_file | sort -t, -n +1 -2 -d +4 -5&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Vincent</description>
      <pubDate>Wed, 04 Jul 2001 05:36:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-problem/m-p/2548625#M875581</guid>
      <dc:creator>Vincent Stedema</dc:creator>
      <dc:date>2001-07-04T05:36:28Z</dc:date>
    </item>
  </channel>
</rss>

