![]() |
|
|
#1 |
|
Guest
Posts: n/a
|
Sorting confusion
Hi all,
I'm having a problem using 'sort' to pre-process log files. I'm not getting my output sorted as I expect: Given an input set: 2007-12-04 20:33:10.587532 "35:1196800053:389002" a 2007-12-04 20:30:25.384069 "35:1196800053:389002" b 2007-12-04 20:33:25.384069 "25:1196800053:389002" c (fields are date, time, session id, something else) I want to sort by the session id then by the time: sort -t \t -k 3,3 -k 1,2 <test 2007-12-04 20:30:25.384069 "35:1196800053:389002" b 2007-12-04 20:33:10.587532 "35:1196800053:389002" a 2007-12-04 20:33:25.384069 "25:1196800053:389002" c I would expect the last entry to be first ("25...<"35...) instead output seems to sorted on k2. It not due to sort getting confused about the order of keys: sort -t \t -k 3,3 <test 2007-12-04 20:30:25.384069 "35:1196800053:389002" b 2007-12-04 20:33:10.587532 "35:1196800053:389002" a 2007-12-04 20:33:25.384069 "25:1196800053:389002" c lowest session id still comes last. sort --version reports: sort (GNU coreutils) 5.97 Copyright (C) 2006 Free Software Foundation, Inc. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Mike Haertel and Paul Eggert. I've tried stripping the quotes around the session id to no avail. If the session id comes in the first column it works OK. I expect I'm doing something stoopid, but I can't for the life of me see what. (yes the seperators are all tabs). Help! C. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: Sorting confusion
In article <>,
C. <> wrote: >sort -t \t -k 3,3 <test >2007-12-04 20:30:25.384069 "35:1196800053:389002" b >2007-12-04 20:33:10.587532 "35:1196800053:389002" a >2007-12-04 20:33:25.384069 "25:1196800053:389002" c -t \t sets the separator to 't', not to TAB. If you do repeat the command by typing sort -t '^V^I' -k 3,3 <test (where ^V is Ctrl+V and ^I is TAB) you'll find that it sorts correctly. If you don't like having invisible formatting in your commands, use sort -t "`echo -e '\t'`" -k 3,3 <test Peter |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Re: Sorting confusion
On Sun, 9 Dec 2007 04:17:44 -0800 (PST), "C."
<> wrote: >Hi all, > >I'm having a problem using 'sort' to pre-process log files. I'm not >getting my output sorted as I expect: > >Given an input set: > >2007-12-04 20:33:10.587532 "35:1196800053:389002" a >2007-12-04 20:30:25.384069 "35:1196800053:389002" b >2007-12-04 20:33:25.384069 "25:1196800053:389002" c > >(fields are date, time, session id, something else) > >I want to sort by the session id then by the time: > > sort -t \t -k 3,3 -k 1,2 <test >2007-12-04 20:30:25.384069 "35:1196800053:389002" b >2007-12-04 20:33:10.587532 "35:1196800053:389002" a >2007-12-04 20:33:25.384069 "25:1196800053:389002" c > >I would expect the last entry to be first ("25...<"35...) instead >output seems to sorted on k2. > >It not due to sort getting confused about the order of keys: > >sort -t \t -k 3,3 <test >2007-12-04 20:30:25.384069 "35:1196800053:389002" b >2007-12-04 20:33:10.587532 "35:1196800053:389002" a >2007-12-04 20:33:25.384069 "25:1196800053:389002" c > >lowest session id still comes last. > >sort --version reports: >sort (GNU coreutils) 5.97 >Copyright (C) 2006 Free Software Foundation, Inc. >This is free software. You may redistribute copies of it under the >terms of >the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. >There is NO WARRANTY, to the extent permitted by law. > >Written by Mike Haertel and Paul Eggert. > >I've tried stripping the quotes around the session id to no avail. If >the session id comes in the first column it works OK. > >I expect I'm doing something stoopid, but I can't for the life of me >see what. > >(yes the seperators are all tabs). > >Help! > >C. It is a shell problem not a sort problem. Try IFS=\t;sort -k 3,3 <test ME |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Re: Sorting confusion
On Sun, 9 Dec 2007 04:17:44 -0800 (PST), "C."
<> wrote: >Hi all, > >I'm having a problem using 'sort' to pre-process log files. I'm not >getting my output sorted as I expect: > >Given an input set: > >2007-12-04 20:33:10.587532 "35:1196800053:389002" a >2007-12-04 20:30:25.384069 "35:1196800053:389002" b >2007-12-04 20:33:25.384069 "25:1196800053:389002" c > >(fields are date, time, session id, something else) > >I want to sort by the session id then by the time: > > sort -t \t -k 3,3 -k 1,2 <test >2007-12-04 20:30:25.384069 "35:1196800053:389002" b >2007-12-04 20:33:10.587532 "35:1196800053:389002" a >2007-12-04 20:33:25.384069 "25:1196800053:389002" c > >I would expect the last entry to be first ("25...<"35...) instead >output seems to sorted on k2. > >It not due to sort getting confused about the order of keys: > >sort -t \t -k 3,3 <test >2007-12-04 20:30:25.384069 "35:1196800053:389002" b >2007-12-04 20:33:10.587532 "35:1196800053:389002" a >2007-12-04 20:33:25.384069 "25:1196800053:389002" c > >lowest session id still comes last. > >sort --version reports: >sort (GNU coreutils) 5.97 >Copyright (C) 2006 Free Software Foundation, Inc. >This is free software. You may redistribute copies of it under the >terms of >the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. >There is NO WARRANTY, to the extent permitted by law. > >Written by Mike Haertel and Paul Eggert. > >I've tried stripping the quotes around the session id to no avail. If >the session id comes in the first column it works OK. > >I expect I'm doing something stoopid, but I can't for the life of me >see what. > >(yes the seperators are all tabs). > >Help! > >C. It is a shell problem not a sort problem. Try IFS=\t;sort -k 3,3 <test ME |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |