|
Home > Archive > Unix Shell > May 2004 > need help sorting a list on date *
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
need help sorting a list on date *
|
|
| Boonie... 2004-05-14, 12:49 pm |
| I'd like to sort this list on the date but i can't get it fixed. It is a
part of a logfile of a FTP server. I'd like to make a script that gives a
list as output that names all the users and the last date they have been
logged in. This is a list for one user. I do not want to use PERL for this.
I tryed sort with the -M option but this only seems to work when the month
has a space before and after it.
Any tips?
Greets, Boonie.
[5] Wed 05May04 15:39:12 - (000065) User FRED logged in
[5] Sat 06Mar04 13:29:57 - (000012) User FRED logged in
[5] Fri 09Jan04 17:36:29 - (000090) User FRED logged in
[5] Sun 11Jan04 10:35:42 - (000004) User FRED logged in
[5] Fri 16Jan04 09:20:00 - (000002) User FRED logged in
[5] Fri 16Jan04 09:44:31 - (000003) User FRED logged in
[5] Tue 17Feb04 14:45:31 - (000018) User FRED logged in
[5] Wed 18Feb04 09:25:40 - (000019) User FRED logged in
[5] Wed 18Feb04 09:39:07 - (000020) User FRED logged in
[5] Tue 20Jan04 19:28:45 - (000007) User FRED logged in
| |
| Kevin Collins 2004-05-14, 2:34 pm |
| In article <40a4f1e9$0$1191$ba620dc5@nova.planet.nl>, Boonie... wrote:
> I'd like to sort this list on the date but i can't get it fixed. It is a
> part of a logfile of a FTP server. I'd like to make a script that gives a
> list as output that names all the users and the last date they have been
> logged in. This is a list for one user. I do not want to use PERL for this.
>
> I tryed sort with the -M option but this only seems to work when the month
> has a space before and after it.
>
> Any tips?
>
> Greets, Boonie.
>
>
> [5] Wed 05May04 15:39:12 - (000065) User FRED logged in
> [5] Sat 06Mar04 13:29:57 - (000012) User FRED logged in
> [5] Fri 09Jan04 17:36:29 - (000090) User FRED logged in
> [5] Sun 11Jan04 10:35:42 - (000004) User FRED logged in
> [5] Fri 16Jan04 09:20:00 - (000002) User FRED logged in
> [5] Fri 16Jan04 09:44:31 - (000003) User FRED logged in
> [5] Tue 17Feb04 14:45:31 - (000018) User FRED logged in
> [5] Wed 18Feb04 09:25:40 - (000019) User FRED logged in
> [5] Wed 18Feb04 09:39:07 - (000020) User FRED logged in
> [5] Tue 20Jan04 19:28:45 - (000007) User FRED logged in
This will do the trick:
sed -e 's/\([0-3][0-9]\)\(Jan\)\([0-9][0-9]\)/\1 \2 \3/' \
-e 's/\([0-3][0-9]\)\(Feb\)\([0-9][0-9]\)/\1 \2 \3/' \
-e 's/\([0-3][0-9]\)\(Mar\)\([0-9][0-9]\)/\1 \2 \3/' \
-e 's/\([0-3][0-9]\)\(Apr\)\([0-9][0-9]\)/\1 \2 \3/' \
-e 's/\([0-3][0-9]\)\(May\)\([0-9][0-9]\)/\1 \2 \3/' \
/your/log/file | \
sort -k4M,4M -k3,3 -k5,5 -k6,6 | \
sed -e 's/\([0-3][0-9]\) \(Jan\) \([0-9][0-9]\)/\1\2\3/' \
-e 's/\([0-3][0-9]\) \(Feb\) \([0-9][0-9]\)/\1\2\3/' \
-e 's/\([0-3][0-9]\) \(Mar\) \([0-9][0-9]\)/\1\2\3/' \
-e 's/\([0-3][0-9]\) \(Apr\) \([0-9][0-9]\)/\1\2\3/' \
-e 's/\([0-3][0-9]\) \(May\) \([0-9][0-9]\)/\1\2\3/'
OR if you gave 'gawk', which supports the gensub() function, you could do:
awk '{
$0=gensub("([0-3][0-9])(Jan|Feb|Mar|May)([0-9][0-9])", "\\1 \\2 \\3", g);
print }' /your/log/file | \
sort -k4M,4M -k3,3 -k5,5 -k6,6 | \
awk '{
$0=gensub("([0-3][0-9]) (Jan|Feb|Mar|May) ([0-9][0-9])", "\\1\\2\\3", g);
print }'
I'll leave it to you to add the rest of the months, and to figure out if you
want the "reversed" date format or not.
Also, this assumes a fairly constant log file format - otherwise your REs might
need to be tighter.
Honestly, though, PERL is the right answer for this, IMO...
Kevin
| |
| Chris F.A. Johnson 2004-05-14, 4:34 pm |
| On 2004-05-14, Boonie... wrote:
> I'd like to sort this list on the date but i can't get it fixed. It is a
> part of a logfile of a FTP server. I'd like to make a script that gives a
> list as output that names all the users and the last date they have been
> logged in. This is a list for one user. I do not want to use PERL for this.
>
> I tryed sort with the -M option but this only seems to work when the month
> has a space before and after it.
>
> [5] Wed 05May04 15:39:12 - (000065) User FRED logged in
> [5] Sat 06Mar04 13:29:57 - (000012) User FRED logged in
> [5] Fri 09Jan04 17:36:29 - (000090) User FRED logged in
> [5] Sun 11Jan04 10:35:42 - (000004) User FRED logged in
> [5] Fri 16Jan04 09:20:00 - (000002) User FRED logged in
> [5] Fri 16Jan04 09:44:31 - (000003) User FRED logged in
> [5] Tue 17Feb04 14:45:31 - (000018) User FRED logged in
> [5] Wed 18Feb04 09:25:40 - (000019) User FRED logged in
> [5] Wed 18Feb04 09:39:07 - (000020) User FRED logged in
> [5] Tue 20Jan04 19:28:45 - (000007) User FRED logged in
Then insert spaces:
awk '{
$3 = substr($3,6,2) " " substr($3,3,3) " " substr($3,1,2)
print
}' FILE | sort -M
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
| Kevin Collins 2004-05-14, 4:34 pm |
| In article <2gkn74F41hthU1@uni-berlin.de>, Chris F.A. Johnson wrote:
> On 2004-05-14, Boonie... wrote:
>
> Then insert spaces:
>
> awk '{
> $3 = substr($3,6,2) " " substr($3,3,3) " " substr($3,1,2)
> print
> }' FILE | sort -M
^^^^^^^
Chris,
that will not give the desired result, as all the fields are not a month.
See my earlier post for the sort command that gives the desired order. Also, I
didn't think about using substr() in my version (regexp based), that's a good
idea!
Kevin
| |
| laura fairhead 2004-05-14, 5:35 pm |
| In article <40a4f1e9$0$1191$ba620dc5@nova.planet.nl>, Boonie... wrote:
>I'd like to sort this list on the date but i can't get it fixed. It is a
>part of a logfile of a FTP server. I'd like to make a script that gives a
>list as output that names all the users and the last date they have been
>logged in. This is a list for one user. I do not want to use PERL for this.
>
>I tryed sort with the -M option but this only seems to work when the month
>has a space before and after it.
>
>Any tips?
Instead of 'perl' you could use 'awk', get the date reformat it
to YYYYMMDD and put it on the start of the line, sort then delete
it -
awk '
BEGIN{ split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",a," ") }
{
if(match($0,"[0-9][0-9][A-Z][a-z][a-z][0-9][0-9] ..:..:..")){
d=""substr($0,RSTART,2); m=""a[substr($0,RSTART+2,3)];
y=2000+substr($0,RSTART+5,2); if(y>2070) y=y-100
print y""m""d""substr($0,RSTART+8,8)" "$0
}
else print "!!!!!!!!!!!!!!!! "$0
} ' filename |sort |cut -d" " -f2-
That doesn't assume a necessary fixed position of the date and
lines that don't seem to have one at all will get preserved..
Why don't you want to use perl?!
wishes,
l
>
>Greets, Boonie.
>
>
>[5] Wed 05May04 15:39:12 - (000065) User FRED logged in
>[5] Sat 06Mar04 13:29:57 - (000012) User FRED logged in
>[5] Fri 09Jan04 17:36:29 - (000090) User FRED logged in
>[5] Sun 11Jan04 10:35:42 - (000004) User FRED logged in
>[5] Fri 16Jan04 09:20:00 - (000002) User FRED logged in
>[5] Fri 16Jan04 09:44:31 - (000003) User FRED logged in
>[5] Tue 17Feb04 14:45:31 - (000018) User FRED logged in
>[5] Wed 18Feb04 09:25:40 - (000019) User FRED logged in
>[5] Wed 18Feb04 09:39:07 - (000020) User FRED logged in
>[5] Tue 20Jan04 19:28:45 - (000007) User FRED logged in
>
>
--
"By deceiving their public through a systematic manufacturing of lies,
their government and their media have abolished democracy for their
own people precisely to the extent to which they have withdrawn the
people's right to truthful information. You can have the best possible
mechanism for democracy, but if you feed it with lies, it cannot
produce results that are humane, honest, and progressive." - Slobodan
Milosevic
| |
| William Park 2004-05-14, 5:35 pm |
| Boonie... <boonie.newsSPAMZUIGT@boonie.fw.nu> wrote:
> I'd like to sort this list on the date but i can't get it fixed. It is a
> part of a logfile of a FTP server. I'd like to make a script that gives a
> list as output that names all the users and the last date they have been
> logged in. This is a list for one user. I do not want to use PERL for this.
>
> I tryed sort with the -M option but this only seems to work when the month
> has a space before and after it.
>
> Any tips?
Put the spaces, sort, and remove spaces.
>
> Greets, Boonie.
>
>
> [5] Wed 05May04 15:39:12 - (000065) User FRED logged in
> [5] Sat 06Mar04 13:29:57 - (000012) User FRED logged in
> [5] Fri 09Jan04 17:36:29 - (000090) User FRED logged in
> [5] Sun 11Jan04 10:35:42 - (000004) User FRED logged in
> [5] Fri 16Jan04 09:20:00 - (000002) User FRED logged in
> [5] Fri 16Jan04 09:44:31 - (000003) User FRED logged in
> [5] Tue 17Feb04 14:45:31 - (000018) User FRED logged in
> [5] Wed 18Feb04 09:25:40 - (000019) User FRED logged in
> [5] Wed 18Feb04 09:39:07 - (000020) User FRED logged in
> [5] Tue 20Jan04 19:28:45 - (000007) User FRED logged in
>
>
--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution/training/migration, Thin-client
| |
| Chris F.A. Johnson 2004-05-14, 6:34 pm |
| On 2004-05-14, Kevin Collins wrote:
> In article <2gkn74F41hthU1@uni-berlin.de>, Chris F.A. Johnson wrote:
> ^^^^^^^
>
> Chris,
>
> that will not give the desired result, as all the fields are not a month.
True; it looked right with a quick glance (and the OP stated that
it worked with a space before and after the month name).
> See my earlier post for the sort command that gives the desired order. Also, I
> didn't think about using substr() in my version (regexp based), that's a good
> idea!
And I wouldn't have considered gensub() unless the portable syntax
proved unworkable.
awk '
BEGIN { months = "JanFebMarAprMayJunJulAugSepOctNovDec" }
{
m = index( months, substr($3,3,3) ) / 3 + 1
printf "%02d%02d%02d\t", substr($3,6,2), m, substr($3,1,2)
print
}' FILE | sort -n | cut -f2
Of course, the entire script could be written easily in awk, e.g.:
awk '
BEGIN { months = "JanFebMarAprMayJunJulAugSepOctNovDec" }
{
m = int(index( months, substr($3,3,3) ) / 3)
d = sprintf( "%02d%02d%02d", substr($3,6,2), m, substr($3,1,2))
if ( d > last[$8] ) last[$8] = d
}
END {
for (user in last) {
year = substr(last[user],1,2)
m = substr(last[user],3,2)
day = substr(last[user],5,2)
month = substr( months, m * 3 + 1, 3 )
printf "%s %02d %s %02d %d\n", user, year, month, day, m
}
}
' LOGFILE
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
| Boonie... 2004-05-16, 10:34 am |
|
Wow guys, that is a lot of response. I hope to find some time to work on it
tomorrow.
Thanks to you all. I'm pretty sure i'll get it done with all this
information.
Thanks again.
Boonie
| |
| John L 2004-05-16, 10:34 am |
|
"Boonie..." <boonie.newsSPAMZUIGT@boonie.fw.nu> wrote in message news:40a4f1e9$0$1191$ba620dc5@nova.planet.nl...
> I'd like to sort this list on the date but i can't get it fixed. It is a
> part of a logfile of a FTP server. I'd like to make a script that gives a
> list as output that names all the users and the last date they have been
> logged in. This is a list for one user. I do not want to use PERL for this.
>
> I tryed sort with the -M option but this only seems to work when the month
> has a space before and after it.
>
Are you sure? Gnu sort -M works without spaces, and
I'd imagine others do as well. What you will need to do
though is to sort the date as three separate keys:
sorting first by the year (-n), then month, then day (-n)
specifying the character positions within the date field
which correspond to day, month and year.
--
John.
| |
| Boonie... 2004-05-16, 11:34 am |
|
"laura fairhead" <laura_fairhead@INVALID.com> schreef in bericht
news:slrncaag05.fh.laura_fairhead@bell486.bittersweet.org...
>
> Instead of 'perl' you could use 'awk', get the date reformat it
> to YYYYMMDD and put it on the start of the line, sort then delete
> it -
>
> awk '
> BEGIN{ split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",a," ") }
> {
> if(match($0,"[0-9][0-9][A-Z][a-z][a-z][0-9][0-9] ..:..:..")){
> d=""substr($0,RSTART,2); m=""a[substr($0,RSTART+2,3)];
> y=2000+substr($0,RSTART+5,2); if(y>2070) y=y-100
> print y""m""d""substr($0,RSTART+8,8)" "$0
> }
> else print "!!!!!!!!!!!!!!!! "$0
> } ' filename |sort |cut -d" " -f2-
I just could not wait.... So I started today ;)
I could not find out what the a[ ..... ] is for. And it would not give the
name of the month so I removed the a and the two brackets. (line 5) I also
added a space between the fields to make it more readable for now. So for
the splitting and separating the first part is perfect now.
Here is the output:
2004 Feb 17 14:45:31 [5] Tue 17Feb04 14:45:31 - (000018) User FRED logged in
2004 Feb 18 09:25:40 [5] Wed 18Feb04 09:25:40 - (000019) User FRED logged in
2004 Feb 18 09:39:07 [5] Wed 18Feb04 09:39:07 - (000020) User FRED logged in
2004 Jan 09 17:36:29 [5] Fri 09Jan04 17:36:29 - (000090) User FRED logged in
2004 Jan 11 10:35:42 [5] Sun 11Jan04 10:35:42 - (000004) User FRED logged in
2004 Jan 16 09:20:00 [5] Fri 16Jan04 09:20:00 - (000002) User FRED logged in
2004 Jan 16 09:44:31 [5] Fri 16Jan04 09:44:31 - (000003) User FRED logged in
2004 Jan 20 19:28:45 [5] Tue 20Jan04 19:28:45 - (000007) User FRED logged in
2004 Mar 06 13:29:57 [5] Sat 06Mar04 13:29:57 - (000012) User FRED logged in
2004 May 05 15:39:12 [5] Wed 05May04 15:39:12 - (000065) User FRED logged in
Now my next problem is that the sort -M command does not seem to do what it
should. So i think i'll try to substitute the month-names for month-numbers.
That will make the sorting part much simpler.
Any ideas on how to do this?
Next thing I'm going to buy is a AWK manual ;)
Thanks for your help,
Boonie
| |
| John L 2004-05-16, 11:34 am |
|
"Boonie..." <boonie.newsSPAMZUIGT@boonie.fw.nu> wrote in message news:40a78403$0$1181$ba620dc5@nova.planet.nl...
>
>
> Now my next problem is that the sort -M command does not seem to do what it
> should. So i think i'll try to substitute the month-names for month-numbers.
> That will make the sorting part much simpler.
>
Are you sure? Which version of sort are you using?
As mentioned elsethread, you probably just need to
specify character positions as part of the arguments
to -k
--
John.
| |
| Boonie... 2004-05-16, 3:34 pm |
|
"John L" <jl@lammtarra.fslife.co.uk> schreef in bericht
news:c87u1c$jlt$1@news5.svr.pol.co.uk...
>
> Are you sure? Gnu sort -M works without spaces, and
> I'd imagine others do as well. What you will need to do
> though is to sort the date as three separate keys:
> sorting first by the year (-n), then month, then day (-n)
> specifying the character positions within the date field
> which correspond to day, month and year.
>
> --
> John.
I used awk to only show me the 4th collumn. This makes me get a collumn with
only months. I've tryed all sorts of combinations after the sort command
except the correct one.
I'm using a gento linux machine with the BASH shell.
I'll try again. It just has to work somehow. The language is the handicap
I'm experiencing I think.
Thanks, Boonie
| |
| Boonie... 2004-05-16, 3:34 pm |
|
"John L" <jl@lammtarra.fslife.co.uk> schreef in bericht
news:c87u1c$jlt$1@news5.svr.pol.co.uk...
>
> Are you sure? Gnu sort -M works without spaces, and
> I'd imagine others do as well. What you will need to do
> though is to sort the date as three separate keys:
> sorting first by the year (-n), then month, then day (-n)
> specifying the character positions within the date field
> which correspond to day, month and year.
Both ways won't work here. So my next option is to translate evey mont into
a number. The the year-month-day (in numbers) should be sorted with a
standard sort.
Boonie.
../sss | sort +0M
Feb
Feb
Feb
Jan
Jan
Jan
Jan
Jan
Mar
May
../sss | sort -k 1M
Feb
Feb
Feb
Jan
Jan
Jan
Jan
Jan
Mar
May
| |
| Boonie... 2004-05-16, 3:34 pm |
|
"John L" <jl@lammtarra.fslife.co.uk> schreef in bericht
news:c880g4$m20$1@news6.svr.pol.co.uk...
>
> Are you sure? Which version of sort are you using?
Is this an answer? Is't from the last line in the MAN pages.
sort (coreutils) 5.0.91 January 2004
Boonie
| |
| Chris F.A. Johnson 2004-05-16, 4:34 pm |
| On 2004-05-16, Boonie... wrote:
>
> "John L" <jl@lammtarra.fslife.co.uk> schreef in bericht
> news:c87u1c$jlt$1@news5.svr.pol.co.uk...
>
>
> Both ways won't work here. So my next option is to translate evey mont into
> a number. The the year-month-day (in numbers) should be sorted with a
> standard sort.
Did you try my suggestion (either one)?
<http://groups.google.com/groups?hl=...40uni-berlin.de>
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
| John L 2004-05-16, 4:34 pm |
|
"Boonie..." <boonie.newsSPAMZUIGT@boonie.fw.nu> wrote in message news:40a7c03f$0$1175$ba620dc5@nova.planet.nl...
>
> "John L" <jl@lammtarra.fslife.co.uk> schreef in bericht
> news:c87u1c$jlt$1@news5.svr.pol.co.uk...
>
>
> Both ways won't work here. So my next option is to translate evey mont into
> a number. The the year-month-day (in numbers) should be sorted with a
> standard sort.
>
> Boonie.
>
> ./sss | sort +0M
> Feb
> Feb
> Feb
> Jan
> Jan
> Jan
> Jan
> Jan
> Mar
> May
>
>
> ./sss | sort -k 1M
> Feb
> Feb
> Feb
> Jan
> Jan
> Jan
> Jan
> Jan
> Mar
> May
>
>
That is odd. Maybe it is an internationalisation issue.
What locale are you using and what are the month names
in the corresponding language?
--
John.
| |
| Boonie... 2004-05-16, 4:34 pm |
|
"Chris F.A. Johnson" <c.fa.johnson@rogers.com> schreef in bericht
news:2gpv1jF5erprU1@uni-berlin.de...
>
> Did you try my suggestion (either one)?
>
>
<http://groups.google.com/groups?hl=...74F41hthU1%40un
i-berlin.de>
Thanks Chris,
Yes I did but could not get it to work. It looks like the sort -M won't do
what it should do but it could sure be my mistake.
I'm about to post the script that did the trick. Your comment on that is
welcome.
Boonie
| |
| Boonie... 2004-05-16, 4:34 pm |
|
"John L" <jl@lammtarra.fslife.co.uk> schreef in bericht
news:c88gu0$ubk$1@newsg1.svr.pol.co.uk...
>
> That is odd. Maybe it is an internationalisation issue.
> What locale are you using and what are the month names
> in the corresponding language?
I'm in The Netherlands and the machine I'm working on is too. Here is the
resonse to te date command. I think this is standard output. No problem.
Sun May 16 22:10:52 CEST 2004
Never seen the locale command (?) before but it gives an output:
ftp log $ locale
LANG=POSIX
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
I'm about to post the script that did the job bus I'm eager to learn more.
Any other sollutions except PERL i'll try. Not PERL because I'dd like to
learn on normal shell script first.
Thanks, Boonie.
| |
| Chris F.A. Johnson 2004-05-16, 4:34 pm |
| On 2004-05-16, Boonie... wrote:
>
> "Chris F.A. Johnson" <c.fa.johnson@rogers.com> schreef in bericht
> news:2gpv1jF5erprU1@uni-berlin.de...
><http://groups.google.com/groups?hl=...40uni-berlin.de>
>
> Thanks Chris,
>
> Yes I did but could not get it to work. It looks like the sort -M won't do
> what it should do but it could sure be my mistake.
I didn't use sort -M (except in my first, incorrect post).
awk '
BEGIN { months = "JanFebMarAprMayJunJulAugSepOctNovDec" }
{
m = index( months, substr($3,3,3) ) / 3 + 1
printf "%02d%02d%02d\t", substr($3,6,2), m, substr($3,1,2)
print
}' FILE | sort -n | cut -f2
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
| Carl Lowenstein 2004-05-17, 12:33 am |
| In article <40a7cab4$0$1193$ba620dc5@nova.planet.nl>,
Boonie... <boonie.newsSPAMZUIGT@boonie.fw.nu> wrote:
>
>"Chris F.A. Johnson" <c.fa.johnson@rogers.com> schreef in bericht
>news:2gpv1jF5erprU1@uni-berlin.de...
><http://groups.google.com/groups?hl=...74F41hthU1%40un
>i-berlin.de>
>
>Thanks Chris,
>
>Yes I did but could not get it to work. It looks like the sort -M won't do
>what it should do but it could sure be my mistake.
As a matter of curiosity, I just tried "sort -M" on a few systems.
It does not sort by month sequence with GNU sort (coreutils) 5.0 on a
Linux system.
It works as expected with sort (GNU textutils) 2.0 on a Linux system.
It works as expected with Sun/Solaris 2.7 /usr/bin/sort.
It works as expected with GNU textutils 2.0 on the same Solaris system.
So something got lost as "sort" was moved from textutils to coreutils.
carl
--
carl lowenstein marine physical lab u.c. san diego
clowenst@ucsd.edu
| |
| John L 2004-05-17, 2:36 am |
|
"Carl Lowenstein" <cdl@deeptow.ucsd.edu> wrote in message news:c89cqi$p9c$1@news1.ucsd.edu...
> In article <40a7cab4$0$1193$ba620dc5@nova.planet.nl>,
> Boonie... <boonie.newsSPAMZUIGT@boonie.fw.nu> wrote:
>
> As a matter of curiosity, I just tried "sort -M" on a few systems.
> It does not sort by month sequence with GNU sort (coreutils) 5.0 on a
> Linux system.
> It works as expected with sort (GNU textutils) 2.0 on a Linux system.
> It works as expected with Sun/Solaris 2.7 /usr/bin/sort.
> It works as expected with GNU textutils 2.0 on the same Solaris system.
>
> So something got lost as "sort" was moved from textutils to coreutils.
>
Have you logged it as a bug?
--
John.
| |
| Carl Lowenstein 2004-05-17, 7:34 pm |
| cdl@deeptow.ucsd.edu (Carl Lowenstein) wrote in message news:<c89cqi$p9c$1@news1.ucsd.edu>...
>
> As a matter of curiosity, I just tried "sort -M" on a few systems.
> It does not sort by month sequence with GNU sort (coreutils) 5.0 on a
> Linux system.
> It works as expected with sort (GNU textutils) 2.0 on a Linux system.
> It works as expected with Sun/Solaris 2.7 /usr/bin/sort.
> It works as expected with GNU textutils 2.0 on the same Solaris system.
>
> So something got lost as "sort" was moved from textutils to coreutils
>
Seems to be fixed in coreutils 5.2 as compiled from GNU source, tested
on a Fedora Core 1 Linux system, which is the one on which coreutils 5.0
fails to sort by Month.
I could not find any mention of this problem in the ChangeLog or NEWS
files. As background information, for all of these tests on all systems,
LC_COLLATE=POSIX.
I have just found that changing LC_CTYPE from en_US.UTF-8 to en_US or to POSIX
causes coreutils 5.0 "sort -M" to do the expected thing.
The interaction between locale parameters and sort behavior is confusing.
carl
| |
| Boonie... 2004-05-18, 9:18 am |
|
"Chris F.A. Johnson" <c.fa.johnson@rogers.com> schreef in bericht
news:2gq1teF5j8g6U2@uni-berlin.de...
>
> I didn't use sort -M (except in my first, incorrect post).
>
> awk '
> BEGIN { months = "JanFebMarAprMayJunJulAugSepOctNovDec" }
> {
> m = index( months, substr($3,3,3) ) / 3 + 1
> printf "%02d%02d%02d\t", substr($3,6,2), m, substr($3,1,2)
> print
> }' FILE | sort -n | cut -f2
Thanks Chris,
I tryed this and it works great. I've allready posted a working sollution 2
days ago. The part for sorting by date is quite similar to your method. Your
sollution is two rows shorter and has less characters so I think I prefer
that.
Thanks again. Boonie
|
|
|
|
|