<?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/4369771#M347152</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;maybe you made it more complicate then simply?&lt;BR /&gt;Where does the '8' comes from?&lt;BR /&gt;Is it the last number of the previous column?&lt;BR /&gt;Can you give a better sample?&lt;BR /&gt;&lt;BR /&gt;Volkmar&lt;BR /&gt;</description>
    <pubDate>Mon, 02 Mar 2009 16:17:24 GMT</pubDate>
    <dc:creator>V. Nyga</dc:creator>
    <dc:date>2009-03-02T16:17:24Z</dc:date>
    <item>
      <title>Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369766#M347147</link>
      <description>&lt;!--!*#--&gt;I have a fixed file length, with embedded spaces.&lt;BR /&gt;I am trying to sort on the employee number in column 10-19, but I get undesirable results.&lt;BR /&gt;&lt;BR /&gt;File is (file.txt):&lt;BR /&gt;         1998945   Warble&lt;BR /&gt;8        5032      Rebholz&lt;BR /&gt;         1124688   Barrera&lt;BR /&gt;         2327703   Rebholz&lt;BR /&gt;&lt;BR /&gt;Result is:&lt;BR /&gt;         1998945   Warble&lt;BR /&gt;8        5032      Rebholz&lt;BR /&gt;         1124688   Barrera&lt;BR /&gt;         2327703   Rebholz&lt;BR /&gt;&lt;BR /&gt;Command script is:&lt;BR /&gt;&lt;BR /&gt;export LC_COLLATE=en_US.ISO8859-1&lt;BR /&gt;export LC_CTYPE=en_US.ISO8859-1&lt;BR /&gt;export LC_MESSAGES=en_US.ISO8859-1&lt;BR /&gt;export LC_MONETARY=en_US.ISO8859-1&lt;BR /&gt;export LC_NUMERIC=en_US.ISO8859-1&lt;BR /&gt;export LC_TIME=en_US.ISO8859-1&lt;BR /&gt;&lt;BR /&gt;sort -t# -k1.10n,1.19n file.txt -o test.sorted&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2009 15:33:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369766#M347147</guid>
      <dc:creator>maberg</dc:creator>
      <dc:date>2009-03-02T15:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369767#M347148</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Posting a textual attachment of the input file would be more helpful.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 02 Mar 2009 15:39:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369767#M347148</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-03-02T15:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369768#M347149</link>
      <description>I have uploaded the input and sorted files.</description>
      <pubDate>Mon, 02 Mar 2009 15:44:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369768#M347149</guid>
      <dc:creator>maberg</dc:creator>
      <dc:date>2009-03-02T15:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369769#M347150</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;You have unequal numbers of fields as shown with the record with an "8" as the first field.&lt;BR /&gt;&lt;BR /&gt;You could do:&lt;BR /&gt;&lt;BR /&gt;# awk '{if (NF&amp;gt;2) {print $2,$0} else {print $1,$0}}' file|sort -kn1,1|cut -d" " -f2-&lt;BR /&gt;&lt;BR /&gt;...which produces:&lt;BR /&gt;&lt;BR /&gt;8        5032      Rebholz&lt;BR /&gt;         1124688   Barrera&lt;BR /&gt;         1998945   Warble&lt;BR /&gt;         2327703   Rebholz&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2009 16:00:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369769#M347150</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-03-02T16:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369770#M347151</link>
      <description>Thanks for the input, but I am trying to use the sort utility only. I need to apply this to a larger file with the same key information.  I used this smaller file for simplicity. This smaller file had the same issues as the larger file.</description>
      <pubDate>Mon, 02 Mar 2009 16:09:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369770#M347151</guid>
      <dc:creator>maberg</dc:creator>
      <dc:date>2009-03-02T16:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369771#M347152</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;maybe you made it more complicate then simply?&lt;BR /&gt;Where does the '8' comes from?&lt;BR /&gt;Is it the last number of the previous column?&lt;BR /&gt;Can you give a better sample?&lt;BR /&gt;&lt;BR /&gt;Volkmar&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2009 16:17:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369771#M347152</guid>
      <dc:creator>V. Nyga</dc:creator>
      <dc:date>2009-03-02T16:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369772#M347153</link>
      <description>I don't believe you can sort the file sample you gave in the way you expect it to be sorted using just sort command. Sort command does depend on a field separator, which is a space or a tab character unless otherwise specified. &lt;BR /&gt;&lt;BR /&gt;In your example, you are expecting sort to recognize a certain range of characters (say 10-to-19 for the employee number) as a field. It is not going to happen as far as my understanding of sort man pages go. &lt;BR /&gt;&lt;BR /&gt;You will need to use some interim parsing of the input file, otherwise all the spaces trailing any line, in the first field is going to be interpreted as a field separator and your first key field for sort is going to be the employee number, whereas when the line starts with that digit "8" your employee number will be key field 2. So, as JRF said, you have non-uniform fields for sort to interpret. And to be perfectly honest, JRF's solution, using awk in conjunction with sort is the most elegant solution you can come up with in your case. If the pipes in that command chain is not working due to the large input file size, the only thing you can do is to parse that command into separate commands and create interim files as you go. That should give you some flexibility.</description>
      <pubDate>Mon, 02 Mar 2009 16:28:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369772#M347153</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2009-03-02T16:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369773#M347154</link>
      <description>The "8" is another data component in column 1.  It is just a data item. Other data characters can be accounted for in column 1 - 9, but not always.</description>
      <pubDate>Mon, 02 Mar 2009 16:30:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369773#M347154</guid>
      <dc:creator>maberg</dc:creator>
      <dc:date>2009-03-02T16:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369774#M347155</link>
      <description>In order to understand what I mean by the non-uniform fields, do this simple exercise:&lt;BR /&gt;&lt;BR /&gt;$ cat myinputfile | while read line ; do&lt;BR /&gt;f1=`echo $line |cut -c 1-9`&lt;BR /&gt;f2=`echo $line |cut -c 10-19`&lt;BR /&gt;f3=`echo $line |cut -c 20-`&lt;BR /&gt;echo $f1","$f2","$f3&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;and see where the character counted fileds are being cut-off. &lt;BR /&gt;&lt;BR /&gt;Hence the need for some external utility like awk to force them to unformity</description>
      <pubDate>Mon, 02 Mar 2009 16:38:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369774#M347155</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2009-03-02T16:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369775#M347156</link>
      <description>You can try:&lt;BR /&gt;&lt;BR /&gt;sort -t# -k1.10nb,1.19nbb file.txt -o test.sorted</description>
      <pubDate>Mon, 02 Mar 2009 16:45:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369775#M347156</guid>
      <dc:creator>Tingli</dc:creator>
      <dc:date>2009-03-02T16:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369776#M347157</link>
      <description>Or:&lt;BR /&gt;sort -t'#' -k1.10n,1.19n file.txt -o test.sorted</description>
      <pubDate>Mon, 02 Mar 2009 16:50:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369776#M347157</guid>
      <dc:creator>Tingli</dc:creator>
      <dc:date>2009-03-02T16:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369777#M347158</link>
      <description>I did try "sort -t# -k1.10nb,1.19nbb" and this was the result.&lt;BR /&gt;&lt;BR /&gt;I am not trying to hide anything, but the total file length of the actual file is 1250 bytes in total length. It would be too large to effectively work with here since the small file still behaves the same way.&lt;BR /&gt;&lt;BR /&gt;Result:&lt;BR /&gt;         1124688   Barrera&lt;BR /&gt;         1998945   Warble&lt;BR /&gt;         2327703   Rebholz&lt;BR /&gt;8        5032      Rebholz&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2009 16:51:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369777#M347158</guid>
      <dc:creator>maberg</dc:creator>
      <dc:date>2009-03-02T16:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369778#M347159</link>
      <description>The sort utility is supposed to be able to sort fixed file formats. This works fine on a Solaris server. We are migrating away from the Solaris platform.&lt;BR /&gt;&lt;BR /&gt;I tried "sort -t'#' -k1.10n,1.19n" and the result was:&lt;BR /&gt;&lt;BR /&gt;Usage: sort [-AbcdfiMmnru] [-T Directory] [-tCharacter] [-y kilobytes] [-o File]&lt;BR /&gt;           [-k Keydefinition].. [[+Position1][-Position2]].. [-z recsz] [File]..&lt;BR /&gt;         1124688   Barrera&lt;BR /&gt;         1998945   Warble&lt;BR /&gt;         2327703   Rebholz&lt;BR /&gt;8        5032      Rebholz&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2009 16:59:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369778#M347159</guid>
      <dc:creator>maberg</dc:creator>
      <dc:date>2009-03-02T16:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369779#M347160</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The "8" is another data component in column 1. It is just a data item. Other data characters can be accounted for in column 1 - 9, but not always.&lt;BR /&gt;&lt;BR /&gt;Exactly.  It (or any group of characters surrounded by whitespace, as the default field delimiter) constitutes a "field" in your file.  This influences what 'sort()' sees as the n-th field you use as a sort key.&lt;BR /&gt;&lt;BR /&gt;Re-read Mel's explanation of my original post and his second offering to you, too.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Thanks for the input, but I am trying to use the sort utility only.&lt;BR /&gt;&lt;BR /&gt;You _are_ the 'sort' to solve your problem.  You simply need to invariantly define the _field_ you want to sort on.  All I did was to manufacture a temporary sort-key; perform the requisite sort; and snip the manufacture key from the output.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 02 Mar 2009 17:02:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369779#M347160</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-03-02T17:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369780#M347161</link>
      <description>I appreciate everyone's input. It is very helpful to get ALL ideas. I am trying them all and I am trying to give you as much information as I know of about the file details.&lt;BR /&gt;&lt;BR /&gt;I really appreciate the efforts here as I am at my wits end over this....</description>
      <pubDate>Mon, 02 Mar 2009 17:02:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369780#M347161</guid>
      <dc:creator>maberg</dc:creator>
      <dc:date>2009-03-02T17:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369781#M347162</link>
      <description>I am digesting Mel and James information and trying to adapt it. My understanding was the the -t option would cause sort to use the whole record as a fixed field when the -t specified a character not contained within the input record.  The current job has been this way for a long time. I will try your suggestions again and do some tweaking.&lt;BR /&gt;&lt;BR /&gt;Mel's output returned:&lt;BR /&gt;1998945 W,arble,&lt;BR /&gt;8 5032 Re,bholz,&lt;BR /&gt;1124688 B,arrera,&lt;BR /&gt;2327703 R,ebholz,&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2009 17:09:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369781#M347162</guid>
      <dc:creator>maberg</dc:creator>
      <dc:date>2009-03-02T17:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369782#M347163</link>
      <description>Give this a shot:&lt;BR /&gt;&lt;BR /&gt;sort -t'#' -k1.10nb,1.19nb</description>
      <pubDate>Mon, 02 Mar 2009 17:18:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369782#M347163</guid>
      <dc:creator>Tingli</dc:creator>
      <dc:date>2009-03-02T17:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369783#M347164</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; My understanding was the the -t option would cause sort to use the whole record as a fixed field when the -t specified a character not contained within the input record. &lt;BR /&gt;&lt;BR /&gt;OK, I just figured out that that was why you kept specifying '-t#'.  I guess I'm a bit dense today.&lt;BR /&gt;&lt;BR /&gt;This doesn't work on HP-UX as logical as it would seem.  It DOES WORK on AIX (and obviously Solaris) underscoring again that various UNIX dialects differ in the edge cases.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 02 Mar 2009 17:19:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369783#M347164</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-03-02T17:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369784#M347165</link>
      <description>the man page for sort on HPUX lists the -t option.  &lt;BR /&gt;&lt;BR /&gt;you might try -t"#"  or see if "stty -a" is using # for something...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2009 18:07:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369784#M347165</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2009-03-02T18:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sort problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369785#M347166</link>
      <description>&amp;gt;sort -t# -k1.10n,1.19n file.txt -o test.sorted&lt;BR /&gt;&lt;BR /&gt;This looks like the right command except that -o.  You need to use "&amp;gt;" or move it sooner:&lt;BR /&gt;sort -t# -k1.10n,1.19n file.txt &amp;gt; test.sorted&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I tried "sort -t'#' -k1.10n,1.19n" and the result was: Usage: ...&lt;BR /&gt;&lt;BR /&gt;Do you still get that "Usage:" message?</description>
      <pubDate>Mon, 02 Mar 2009 18:15:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-problem/m-p/4369785#M347166</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-03-02T18:15:55Z</dc:date>
    </item>
  </channel>
</rss>

