<?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: Awk query in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198222#M680600</link>
    <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Oops, sorry; disregard the first post.  You want to order _by_number_:&lt;BR /&gt;&lt;BR /&gt;# grep hdiskpower file|sort -nk 1.11&lt;BR /&gt;&lt;BR /&gt;...which makes the sort key numeric beginning with the eleventh (one-relative) character to the end of the line.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
    <pubDate>Wed, 09 Sep 2009 15:40:14 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-09-09T15:40:14Z</dc:date>
    <item>
      <title>Awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198220#M680598</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I'm looking for a routine to sort 'hdiskpower' disk by number.&lt;BR /&gt;&lt;BR /&gt;Input:&lt;BR /&gt;hdisk5&lt;BR /&gt;hdisk22&lt;BR /&gt;hdisk23&lt;BR /&gt;hdisk29&lt;BR /&gt;hdiskpower12&lt;BR /&gt;hdisk12&lt;BR /&gt;hdisk11&lt;BR /&gt;hdisk10&lt;BR /&gt;hdiskpower22&lt;BR /&gt;hdiskpower32&lt;BR /&gt;hdisk8&lt;BR /&gt;hdisk6&lt;BR /&gt;hdisk20&lt;BR /&gt;hdiskpower13&lt;BR /&gt;hdiskpower27&lt;BR /&gt;hdiskpower43&lt;BR /&gt;&lt;BR /&gt;Desire output:&lt;BR /&gt;hdiskpower12&lt;BR /&gt;hdiskpower13&lt;BR /&gt;hdiskpower22&lt;BR /&gt;hdiskpower27&lt;BR /&gt;hdiskpower32&lt;BR /&gt;hdiskpower43&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Sep 2009 13:44:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198220#M680598</guid>
      <dc:creator>user57</dc:creator>
      <dc:date>2009-09-09T13:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198221#M680599</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;# grep hdiskpower file|sort&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 09 Sep 2009 13:55:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198221#M680599</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-09T13:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198222#M680600</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Oops, sorry; disregard the first post.  You want to order _by_number_:&lt;BR /&gt;&lt;BR /&gt;# grep hdiskpower file|sort -nk 1.11&lt;BR /&gt;&lt;BR /&gt;...which makes the sort key numeric beginning with the eleventh (one-relative) character to the end of the line.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Sep 2009 15:40:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198222#M680600</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-09T15:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: Awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198223#M680601</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;As JRF outlines, the regular sort has enough power to solve this if the data is either fixed  columns and/or in easy delimited fields. If there is no clear delimiter, then maybe you can add one just for the sort, do the sort, and remove the delimiter.&lt;BR /&gt;Something like:&lt;BR /&gt;&lt;BR /&gt;# perl -pe "s/(\d)/~\1/" tmp.txt | sort -t~  -k1,2.n | perl -pe "s/~//"&lt;BR /&gt;&lt;BR /&gt;For more complex comparisons I often prefer to explicitly peel apart the the fields and use the desired transformations on them perl.&lt;BR /&gt;&lt;BR /&gt;For example for this simple case:&lt;BR /&gt;&lt;BR /&gt;As a 'one-liner' :&lt;BR /&gt;$ perl -ne 'm/(^\D+)(\d+)$/;$nam{$.}=$1;$num{$.}=$2 }{ for (sort {$nam{$a} cmp $nam{$b} or $num{$a}&lt;BR /&gt; &amp;lt;=&amp;gt; $num{$b}} keys %nam) { print "$nam{$_}$num{$_}\n"}' tmp.txt&lt;BR /&gt;&lt;BR /&gt;hdisk5&lt;BR /&gt;hdisk6&lt;BR /&gt;hdisk8&lt;BR /&gt;hdisk10&lt;BR /&gt;hdisk11&lt;BR /&gt;hdisk12&lt;BR /&gt;hdisk20&lt;BR /&gt;hdisk22&lt;BR /&gt;hdisk23&lt;BR /&gt;hdisk29&lt;BR /&gt;hdiskpower12&lt;BR /&gt;hdiskpower13&lt;BR /&gt;hdiskpower22&lt;BR /&gt;hdiskpower27&lt;BR /&gt;hdiskpower32&lt;BR /&gt;hdiskpower43&lt;BR /&gt;&lt;BR /&gt;In slow motion&lt;BR /&gt;&lt;BR /&gt;$ perl -ne '  # loop over input, do no print&lt;BR /&gt;m/(^\D+)(\d+)$/;   # match on non-decimal and decimals&lt;BR /&gt;$nam{$.}=$1;     # store the name part&lt;BR /&gt;$num{$.}=$2      # store the numeric part&lt;BR /&gt;}{               # end the read block, start the end block&lt;BR /&gt;&lt;BR /&gt;for (sort {      # sort with function being...&lt;BR /&gt;$nam{$a} cmp $nam{$b} # first by name &lt;BR /&gt;or                # if 0 = equal then&lt;BR /&gt;$num{$a} &amp;lt;=&amp;gt; $num{$b} # next by numbers&lt;BR /&gt;} keys %nam) # to be sorted is the keys (line numbers)&lt;BR /&gt;{ print           # action!&lt;BR /&gt;"$nam{$_}$num{$_}\n" # reconstruct line&lt;BR /&gt;}' tmp.txt   # and action, end command, input&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Sep 2009 17:06:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198223#M680601</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2009-09-09T17:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198224#M680602</link>
      <description>Thanks for the solutions</description>
      <pubDate>Thu, 10 Sep 2009 06:46:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198224#M680602</guid>
      <dc:creator>user57</dc:creator>
      <dc:date>2009-09-10T06:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198225#M680603</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;I see that you are new to this Forum.  Welcome!&lt;BR /&gt;&lt;BR /&gt;That said, please read the link below about points.  Points are not only a way of saying "thanks!" but bread-crumbs for future trollers to find the tastiest (most applicable) solution:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/helptips.do?#28" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/helptips.do?#28&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 10 Sep 2009 10:16:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198225#M680603</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-10T10:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198226#M680604</link>
      <description>Also, in future do not open two threads with the same subject.&lt;BR /&gt;My initial view was these were duplicate, and I was about to delete one.</description>
      <pubDate>Thu, 10 Sep 2009 10:52:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/5198226#M680604</guid>
      <dc:creator>melvyn burnard</dc:creator>
      <dc:date>2009-09-10T10:52:03Z</dc:date>
    </item>
  </channel>
</rss>

