<?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: uniq sort and group in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607944#M104264</link>
    <description>Thanks Muthu. It is exactly what I was looking for.&lt;BR /&gt;&lt;BR /&gt;Yashy.</description>
    <pubDate>Mon, 22 Aug 2005 23:51:26 GMT</pubDate>
    <dc:creator>Yashy</dc:creator>
    <dc:date>2005-08-22T23:51:26Z</dc:date>
    <item>
      <title>uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607935#M104255</link>
      <description>Hi,&lt;BR /&gt;I have a text file like below which has several hundred lines.&lt;BR /&gt;&lt;BR /&gt;createuser ba026860 ac50003000&lt;BR /&gt;createuser na027483 ae50007009&lt;BR /&gt;createuser rax78895 af60003001&lt;BR /&gt;createuser tmxr8983 af50003001&lt;BR /&gt;&lt;BR /&gt;The 3rd field in 3rd and 4th line is same. I want to sort it on the third field first, and print the output of the third field as uniq (grouping); like below (if the 3rd field has the same value; then group and print only one time as below:&lt;BR /&gt;&lt;BR /&gt;createuser ba026860 ac50003000&lt;BR /&gt;createuser na027483 ae50007009&lt;BR /&gt;createuser rax78895 af60003001&lt;BR /&gt;createuser tmxr8983 &lt;BR /&gt;&lt;BR /&gt;Please advise.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Sat, 20 Aug 2005 05:48:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607935#M104255</guid>
      <dc:creator>Yashy</dc:creator>
      <dc:date>2005-08-20T05:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607936#M104256</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;In order to sort a file by 3rd field you can use the command:&lt;BR /&gt;sort -k 3 filename&lt;BR /&gt;For the desired output you can use awk:&lt;BR /&gt;sort -k 3 filename| awk '{if($3!=prev){prev=$3;print}}'&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Aug 2005 09:33:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607936#M104256</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2005-08-20T09:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607937#M104257</link>
      <description>Hi,&lt;BR /&gt;Sort the file on the third fild first.&lt;BR /&gt;Then, use the command "uniq -f 2 &lt;FILE&gt;".&lt;BR /&gt;&lt;BR /&gt;The option "-f 2" ignores the first two filds when comparing the lines. Else the entire line is compared.&lt;/FILE&gt;</description>
      <pubDate>Sat, 20 Aug 2005 09:34:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607937#M104257</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-08-20T09:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607938#M104258</link>
      <description>It does not work. I still get the output same as sort -k3</description>
      <pubDate>Sat, 20 Aug 2005 23:36:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607938#M104258</guid>
      <dc:creator>Yashy</dc:creator>
      <dc:date>2005-08-20T23:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607939#M104259</link>
      <description>Sorry. The source file is like this&lt;BR /&gt;&lt;BR /&gt;createuser ba026860 ac50003000&lt;BR /&gt;createuser na027483 ae50007009&lt;BR /&gt;createuser rax78895 af50003001&lt;BR /&gt;createuser tmxr8983 af50003001&lt;BR /&gt;&lt;BR /&gt;The 3rd field in the last two lines are same.&lt;BR /&gt;So I need the result to come as below:&lt;BR /&gt;&lt;BR /&gt;createuser ba026860 ac50003000&lt;BR /&gt;createuser na027483 ae50007009&lt;BR /&gt;createuser rax78895 af50003001&lt;BR /&gt;createuser tmxr8983 &lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Sun, 21 Aug 2005 00:46:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607939#M104259</guid>
      <dc:creator>Yashy</dc:creator>
      <dc:date>2005-08-21T00:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607940#M104260</link>
      <description>&lt;BR /&gt;Minor tweak on Victor's reply gets the desired output:&lt;BR /&gt;&lt;BR /&gt;sort -k 3 your-file | awk '{x=($3==old)? "" : $3; old=$3; print $1,$2,x}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;For more complex options you may want to use a perl frame work and then tweak that.&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;-------------------- group.p ---------&lt;BR /&gt;%lines = &amp;lt;&amp;gt;;&lt;BR /&gt;sub sort_3_2 {&lt;BR /&gt;  ($a1,$a2,$a3) = split(/\s+/,$a);&lt;BR /&gt;  ($b1,$b2,$b3) = split(/\s+/,$b);&lt;BR /&gt;  $a3.$a2 cmp $b3.$b2&lt;BR /&gt;  }&lt;BR /&gt;foreach (sort sort_3_2 %lines) {&lt;BR /&gt;  ($a1,$a2,$a3) = split;&lt;BR /&gt;  $x3 = ($a3 eq $old)? "" : $a3;&lt;BR /&gt;  print "$a1 $a2 $x3\n";&lt;BR /&gt;  $old = $a3;&lt;BR /&gt;  }&lt;BR /&gt;--------------------------------&lt;BR /&gt;&lt;BR /&gt;perl group.p your-file&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Aug 2005 01:22:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607940#M104260</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-08-21T01:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607941#M104261</link>
      <description>Hi Hein&lt;BR /&gt;&lt;BR /&gt;The awk one does not work. The perl one works. But I cannot implement here as I do not know perl.&lt;BR /&gt;&lt;BR /&gt;Can you please check the awk on. &lt;BR /&gt;&lt;BR /&gt;This is the error I get form the awk.&lt;BR /&gt;awk: syntax error near line 1&lt;BR /&gt;awk: illegal statement near line 1&lt;BR /&gt;&lt;BR /&gt;thanks.</description>
      <pubDate>Sun, 21 Aug 2005 04:37:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607941#M104261</guid>
      <dc:creator>Yashy</dc:creator>
      <dc:date>2005-08-21T04:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607942#M104262</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;Hmmm, the awk one really seems to work for me.&lt;BR /&gt;Did you re-type or cut &amp;amp; paste (and change the file name)&lt;BR /&gt;&lt;BR /&gt;% uname -a&lt;BR /&gt;HP-UX hpgsp05c B.11.11 U 9000/800 690339353 unlimited-user license&lt;BR /&gt;% cat x&lt;BR /&gt;createuser ba026860 ac50003000&lt;BR /&gt;createuser na027483 ae50007009&lt;BR /&gt;createuser rax78895 af50003001&lt;BR /&gt;createuser tmxr8983 af50003001&lt;BR /&gt;createuser ba026861 ac50003000&lt;BR /&gt;createuser na027483 ae50007009&lt;BR /&gt;createuser na027485 ae50007009&lt;BR /&gt;createuser na027484 ae50007009&lt;BR /&gt;createuser rax78895 af50003001&lt;BR /&gt;createuser tmxr8983 af50003001&lt;BR /&gt;% sort -k 3 x | awk '{x=($3==old)? "" : $3; old=$3; print $1,$2,x}'&lt;BR /&gt;createuser ba026860 ac50003000&lt;BR /&gt;createuser ba026861&lt;BR /&gt;createuser na027483 ae50007009&lt;BR /&gt;createuser na027483&lt;BR /&gt;createuser na027484&lt;BR /&gt;createuser na027485&lt;BR /&gt;createuser rax78895 af50003001&lt;BR /&gt;createuser rax78895&lt;BR /&gt;createuser tmxr8983&lt;BR /&gt;createuser tmxr8983&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Aug 2005 09:54:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607942#M104262</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-08-21T09:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607943#M104263</link>
      <description>You can do it as,&lt;BR /&gt;&lt;BR /&gt;sort -k 3 &lt;FILENAME&gt; | awk '{ if ( prev != $3 ) { prev=$3;print; } else { print $1" "$2 }}'&lt;BR /&gt;&lt;BR /&gt;hth.&lt;/FILENAME&gt;</description>
      <pubDate>Mon, 22 Aug 2005 00:31:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607943#M104263</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-22T00:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: uniq sort and group</title>
      <link>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607944#M104264</link>
      <description>Thanks Muthu. It is exactly what I was looking for.&lt;BR /&gt;&lt;BR /&gt;Yashy.</description>
      <pubDate>Mon, 22 Aug 2005 23:51:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/uniq-sort-and-group/m-p/3607944#M104264</guid>
      <dc:creator>Yashy</dc:creator>
      <dc:date>2005-08-22T23:51:26Z</dc:date>
    </item>
  </channel>
</rss>

