<?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 question. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813552#M827508</link>
    <description>Another caveat.  The file needs to stay in the same format or the web log analyzer won't be able to parse it.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 25 Sep 2002 22:19:41 GMT</pubDate>
    <dc:creator>Sean OB_1</dc:creator>
    <dc:date>2002-09-25T22:19:41Z</dc:date>
    <item>
      <title>Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813546#M827502</link>
      <description>This should be easy.&lt;BR /&gt;&lt;BR /&gt;I have a web log file with format of:&lt;BR /&gt;66.196.65.25 - - [17/Sep/2002:09:00:57 -0500] "GET /robots.txt&lt;BR /&gt;&lt;BR /&gt;I need to sort by date.  So sort by month (Sep), day (17), time (09:00:57).&lt;BR /&gt;&lt;BR /&gt;What's the easiest way to do so?&lt;BR /&gt;&lt;BR /&gt;TIA,&lt;BR /&gt;&lt;BR /&gt;Sean</description>
      <pubDate>Wed, 25 Sep 2002 20:08:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813546#M827502</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-25T20:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813547#M827503</link>
      <description>Hi Sean:&lt;BR /&gt;&lt;BR /&gt;I'd use something like this:&lt;BR /&gt;&lt;BR /&gt;# sort -t/ -k3 -kM2 -k1 filein&lt;BR /&gt;&lt;BR /&gt;This uses the "/" as the field delimiter.  The '-M' signifies the third field should be compared as months.  See the 'sort' man pages for an explanation.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 25 Sep 2002 20:25:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813547#M827503</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-09-25T20:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813548#M827504</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;Wouldn't that only sort on Month and then the first field, which starts with IP address?  &lt;BR /&gt;&lt;BR /&gt;I've read the man on sort and didn't see any way to either sort on a column, or specify more than one deliminator, say "/" and "[".&lt;BR /&gt;&lt;BR /&gt;Sean&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Sep 2002 20:30:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813548#M827504</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-25T20:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813549#M827505</link>
      <description>Hi (again) Sean:&lt;BR /&gt;&lt;BR /&gt;Sorry, the month is the second field:&lt;BR /&gt;&lt;BR /&gt;Yes, the first field really consists of the IP address through the day.  The second field is a 3-character month (cleanly), and the third field is a year followed by a time.  Ugly.&lt;BR /&gt;&lt;BR /&gt;It would be helpful to re-format the data before sorting and/or to add a field start/field end to the keys specified.&lt;BR /&gt;&lt;BR /&gt;The "key" [no pun intended, here] is the '-M' option to handle sorting months.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Sep 2002 20:38:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813549#M827505</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-09-25T20:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813550#M827506</link>
      <description>Ok, so now I can do the month field, but how can I also sort on the day and time fields?&lt;BR /&gt;&lt;BR /&gt;That's the part that I couldn't figure out.  I can't sort on field one, as that will put it in ip address order, when I need only the day portion of it.  Ditto for field 3, where I only need the time portion of it.&lt;BR /&gt;&lt;BR /&gt;Sean&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Sep 2002 22:02:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813550#M827506</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-25T22:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813551#M827507</link>
      <description>&lt;BR /&gt;Sean,&lt;BR /&gt;&lt;BR /&gt;You should convert the date/time to the internal format and sort on that! The use of perl comes to mind here!&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Wed, 25 Sep 2002 22:06:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813551#M827507</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-09-25T22:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813552#M827508</link>
      <description>Another caveat.  The file needs to stay in the same format or the web log analyzer won't be able to parse it.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Sep 2002 22:19:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813552#M827508</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-25T22:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813553#M827509</link>
      <description>Does gnu have a sort?&lt;BR /&gt;&lt;BR /&gt;Of course you are going to require that a "set" of transactions stay together??&lt;BR /&gt;&lt;BR /&gt;What you need is a real web log analizer.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Wed, 25 Sep 2002 22:23:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813553#M827509</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-09-25T22:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813554#M827510</link>
      <description>Actually I have a pretty good analyzer, but it doesn't seem to like it when the records come in out of order.&lt;BR /&gt;&lt;BR /&gt;I had to combine log files from about 10 sites into one file, which means that the records are out of order.&lt;BR /&gt;&lt;BR /&gt;So I only need to sort the file on the date fields.  &lt;BR /&gt;</description>
      <pubDate>Wed, 25 Sep 2002 22:39:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813554#M827510</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-25T22:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813555#M827511</link>
      <description>&lt;BR /&gt;Sean,&lt;BR /&gt;&lt;BR /&gt;With perl you could convert the "external date" into the internal date and sort on that date, which would just be an index to the original record.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Wed, 25 Sep 2002 22:41:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813555#M827511</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-09-25T22:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813556#M827512</link>
      <description>Hi Sean&lt;BR /&gt;&lt;BR /&gt;I would try awk to reformat the file .&lt;BR /&gt;You can use the "blank" as Input Field Separator and as Output Filed separator the ";" { FS = " "; OFS = ";" }&lt;BR /&gt;This will deliver you as output :&lt;BR /&gt;66.196.65.25 - - [17/Sep/2002:09:00:57 -0500] "GET /robots.txt in the variables&lt;BR /&gt;$1  $2 $3 $4 $5 $6&lt;BR /&gt;&lt;BR /&gt;$1 = 66.196.65.25&lt;BR /&gt;$2 = -&lt;BR /&gt;$3 = -&lt;BR /&gt;$4 = [17/Sep/2002:09:00:57 &lt;BR /&gt;$5 = -0500]&lt;BR /&gt;$6 = "GET&lt;BR /&gt;$7 = &lt;REST of="" line=""&gt;&lt;BR /&gt;&lt;BR /&gt;Next step is to split $4 into Date and time and store both values in variables&lt;BR /&gt;&lt;BR /&gt;if the date is always in this format then its easy :&lt;BR /&gt;Date = substr( $4,2,11)&lt;BR /&gt;Bracket = substr ( $4,1,1)&lt;BR /&gt;Colon = substr ( $4,12,1 )&lt;BR /&gt;Time = substr ( $4,13,8)&lt;BR /&gt;&lt;BR /&gt;outpuline is :&lt;BR /&gt;&lt;BR /&gt;print $1,$2,$3,Bracket,Date,Colon,Time,$5,$6,$7&lt;BR /&gt;&lt;BR /&gt;You get a line like this&lt;BR /&gt;66.196.65.25;-;-;[;17/Sep/2002;:;09:00:57;-0500;"GET;/robots.txt&lt;BR /&gt;&lt;BR /&gt;Now you can sort on the fields you like.&lt;BR /&gt;Output this again into a file and run again awk to replace the ; by a &lt;BLANK&gt;&lt;BR /&gt;Now you should have a copy of your original file in the same format but sorted.&lt;BR /&gt;&lt;BR /&gt;Following you will find the listing of both awk scripts needed :&lt;BR /&gt;&lt;BR /&gt;script one used to create sortable fields&lt;BR /&gt;&lt;BR /&gt;BEGIN { FS = " " ; OFS = ";" }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;Date = substr( $4,2,11)&lt;BR /&gt;Bracket = substr ( $4,1,1)&lt;BR /&gt;Colon = substr ( $4,13,1 )&lt;BR /&gt;Time = substr ( $4,14,8)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;print $1,$2,$3,Bracket,Date,Colon,Time,$5,$6,$7&lt;BR /&gt;&lt;BR /&gt;}                                         &lt;BR /&gt;#end of script&lt;BR /&gt;&lt;BR /&gt;Script two used to remove ";" after sorting&lt;BR /&gt;&lt;BR /&gt;BEGIN { FS = ";" ; OFS = " " }&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;print $1,$2,$3,$4 $5 $6 $7,$8,$9,$10&lt;BR /&gt;}       &lt;BR /&gt;# $4 to $7 need to be placed WITHOUT a comma in between&lt;BR /&gt;# end of script&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;squence of commands :&lt;BR /&gt;&lt;BR /&gt;awk -f &amp;lt;script one&amp;gt; logfile &amp;gt; logfilecopy1&lt;BR /&gt;sort &lt;USING your="" needed="" sort="" option="" delimiter="" is=""&gt;&lt;BR /&gt;awk -f &amp;lt;script two&amp;gt; logfilecopy2 &amp;gt;logfilecopy2&lt;BR /&gt;&lt;BR /&gt;forward file "logfilecopytwo to your weblog parser. Ithink this should work&lt;BR /&gt;&lt;BR /&gt;Maybe it's not a nice way but it will do it. And there may also be shorter ways,. but as i'm not the big expert on the shell prompt i most often handle it in such sequences.&lt;BR /&gt;Hope it helps&lt;/USING&gt;&lt;/BLANK&gt;&lt;/REST&gt;</description>
      <pubDate>Thu, 26 Sep 2002 05:47:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813556#M827512</guid>
      <dc:creator>Reinhard Burger</dc:creator>
      <dc:date>2002-09-26T05:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813557#M827513</link>
      <description>Hi Sean,&lt;BR /&gt;        the safest way is probably to read the time specification in each line and then  convert month names into numerical values. You should then apply time specs. as a "numerical weight (year, month, day, etc)"  at the end of each line in a temporary file.&lt;BR /&gt;Example: your input:&lt;BR /&gt;       66.196.65.25 - - [17/Sep/2002:09:00:57 -0500] "GET /robots.txt &lt;BR /&gt;&lt;BR /&gt;Temporary output:&lt;BR /&gt;66.196.65.25 - - [17/Sep/2002:09:00:57 -0500] "GET /robots.txt # 20020917090057&lt;BR /&gt;&lt;BR /&gt;Then sort the lines of the temporary file using the "numerical weght" as key, but write out only until the distinctive character.&lt;BR /&gt;The attached script can (perhaps) create the temporary file.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
      <pubDate>Thu, 26 Sep 2002 07:05:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813557#M827513</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2002-09-26T07:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813558#M827514</link>
      <description>Thanks for the help guys, I'll try it today and see if I can get it to work.&lt;BR /&gt;&lt;BR /&gt;Am I right that sort won't let you sort on a column?  That would seem like the most basic requirement of a sort util.  &lt;BR /&gt;&lt;BR /&gt;For example sort on chars in columns 5-10.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Sep 2002 13:40:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813558#M827514</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-26T13:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813559#M827515</link>
      <description>Hi Sean:&lt;BR /&gt;&lt;BR /&gt;You can limit the sort key to character positions within the field.  This is called a restricted sort key.  For instance, if I had a file like:&lt;BR /&gt;&lt;BR /&gt;a999bc&lt;BR /&gt;a123bc&lt;BR /&gt;a011bc&lt;BR /&gt;a099bc&lt;BR /&gt;a456bc&lt;BR /&gt;&lt;BR /&gt;...I could sort on the first field using only positions (columns) two, three and four (the numeric part) with:&lt;BR /&gt;&lt;BR /&gt;# sort sort -k1.2,1.4 filename&lt;BR /&gt;&lt;BR /&gt;This is what I originally suggested when I said, "It would be helpful to re-format the data before sorting and/or to add a field start/field end to the keys specified".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF... &lt;BR /&gt;</description>
      <pubDate>Thu, 26 Sep 2002 13:59:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813559#M827515</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-09-26T13:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813560#M827516</link>
      <description>Here is a one command line that should do it. It extracts the sort fields, reorders them, prefixes them on the line, does the sort, then removes the prefixed keys.&lt;BR /&gt;&lt;BR /&gt;perl -ne 'if (/\[([^\]]+)\]) {@a=split("[:/]",$1);print $a[2]," ",$a[1]," ",@a[0,3,4,5]," ",$_;}' yourlog | sort -k1 -kM2 -k3 | cut -c19- &amp;gt;sortedlog&lt;BR /&gt;&lt;BR /&gt;Hope this helps...&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 26 Sep 2002 15:11:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813560#M827516</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-09-26T15:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sort question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813561#M827517</link>
      <description>Ok, I ended up using a kludge of what Jim suggested.&lt;BR /&gt;&lt;BR /&gt;I used the [ as the delimiter and sorted on the second field.  Fortunately for this file there was only 1 month so I didn't have to worry about getting the month order right.  But for future times I'll have to deal with that.&lt;BR /&gt;&lt;BR /&gt;Thanks for the help.&lt;BR /&gt;&lt;BR /&gt;Sean&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Sep 2002 16:39:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-question/m-p/2813561#M827517</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-26T16:39:42Z</dc:date>
    </item>
  </channel>
</rss>

