[Swift-commit] r2650 - log-processing/libexec/log-processing

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Mon Mar 9 03:30:14 CDT 2009


Author: benc
Date: 2009-03-09 03:30:14 -0500 (Mon, 09 Mar 2009)
New Revision: 2650

Modified:
   log-processing/libexec/log-processing/sort-preserve
Log:
fix timestamp ordering bug in sort-preserve when the timestamp fields
are of different length (which occurs rarely in practice)

Modified: log-processing/libexec/log-processing/sort-preserve
===================================================================
--- log-processing/libexec/log-processing/sort-preserve	2009-03-09 08:29:34 UTC (rev 2649)
+++ log-processing/libexec/log-processing/sort-preserve	2009-03-09 08:30:14 UTC (rev 2650)
@@ -3,8 +3,18 @@
 # sort   name timestamp rest
 #  by name, then by timestamp, then by order in file
 
-# do this by numbering each line as a second field and sorting on that.
+# This differs from sorting on the first two fields. In sort-preserve, where
+# two lines have the same key (the same first two fields), then those two
+# lines will always be output in the same order as they appear in the
+# input file. This is not the case for POSIX sort.
 
+# This by numbering each line as a third field and using that as a third
+# key; and then removing that field after sorting.
+
+# TODO the temporary files should be made properly unique, and removed
+# after use (or removed entirely, with this entire script made into a
+# single pipe)
+
 I=0
 
 while read name timestamp rest; do
@@ -12,7 +22,7 @@
   I=$(( $I + 1 ))
 done > sort-preserve.tmp
 
-sort $@  -n -k 1f,3 < sort-preserve.tmp > sort-preserve2.tmp
+sort $@ -k 1f,1f -k 2n,2n -k 3n,3n < sort-preserve.tmp > sort-preserve2.tmp
 
 sed 's/^\([^ ]*\) \([^ ]*\) \([^ ]*\)\(.*\)/\1 \2\4/' < sort-preserve2.tmp
 




More information about the Swift-commit mailing list