Article View: news.software.readers
Article #43283Re: How can I sort newsgroups?
From: Kim DeVaughn
Date: Fri, 18 Sep 1998 00:00
Date: Fri, 18 Sep 1998 00:00
197 lines
7244 bytes
7244 bytes
In article <6ttop4$nld$1@news2.xs4all.nl>,
Jeroen Scheerder <js@xs4all.nl> wrote:
|
| admin@intergrafix.net:
| >
| > Is there any way to get it to sort my newsgroup list alphabetically (either
| > ascending or descending)?
|
| Exit tin. :-) In the shell, type
|
| $ sort < $HOME/.newsrc > $HOME/.newsrc.sorted
|
| The file .newsrc.sorted is now, well, sorted.
Well, sort of (bad pun intended) ...
Unfortunately, a straight sort collates "-" and "!" before ".", and ":"
after it, which for newsgroups, can lead to inconsistent and/or undesirable
ordering.
For example, I think most people would agree that these newsgroups are
properly sorted:
alt.fan.bruce! 1-81
alt.fan.bruce.woodcock! 1-454
alt.fan.bruce-becker! 1-655
alt.fan.bruce-campbell! 1-8668
alt.fan.bruce-kettler! 1-1420
but a straight "sort" on them, will result in:
alt.fan.bruce! 1-81
alt.fan.bruce-becker! 1-655
alt.fan.bruce-campbell! 1-8668
alt.fan.bruce-kettler! 1-1420
alt.fan.bruce.woodcock! 1-454
unless you happen to be subscribed to alt.fan.bruce, in which case
you get:
alt.fan.bruce-becker: 1-655
alt.fan.bruce-campbell: 1-8668
alt.fan.bruce-kettler: 1-1420
alt.fan.bruce.woodcock: 1-454
alt.fan.bruce: 1-81
Etc.
Enter the recumbent bicyclist, Leo Schwab, who was annoyed enough to
actually do something about it, which he posted in the best.* internal
newsgroups, and which I've been using quite successfully, ever since.
There are probably more elegant (and less cpu intensive) ways of doing
this, but working code in hand ...
I'll leave all the commentary on it, to provide the context of his
efforts. Note that this has been tweaked for perl5, and IIRC, will
need some minor mods for perl4.
Anybody have a better solution that will give the same results ...?
/kim
#---- snip --------------------------------------------------------------------
#!/usr/local/bin/perl5
#
# usage: ngsort infile >outfile
#
#From: ewhac@best.com (Leo L. Schwab)
#Newsgroups: best.general
#Subject: Sorting a .newsrc
#Date: 19 Jan 1997 23:24:11 -0800
#Message-ID: <5bv6ir$93n@shellx.best.com>
#Organization: Verbatim Corp.: Abort, Retry, Ignore, Fail?
#
#
#[ yum ]
#
# I have gotten it into my head to sort my .newsrc file. However, I
#am having trouble working out a proper incantation to do it.
#
# My first thought was to use sort(1), but because you can't force it
#to ignore everything from the ':' or '!' characters onward, some entries
#come out in the wrong place. In particular:
#
#alt.foo.bar: /* will sort before */
#alt.foo:
#
# This because of the way the ':' character compares with '.'.
#
# So then I thought of using Perl to do it (yeah, I know, atomic bomb
#to kill a fly). Well, three hours later, I got nowhere, and decided to
#throw dignity to the wind and post a plea for help here.
#
# All assistance appreciated. Thanks.
#
#_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
#Leo L. Schwab -- Digital Spellweaver ewhac@best.com ..or..
# \_ -_ http://www.best.com/~ewhac/ ewhac@well.com
#O----^o Recumbent Bikes: The Only Way To Fly. (pronounced "EH-wack")
# Hiroshima '45. Chernobyl '86. Windows '95.
#
#==============================================================================
#
#From: doosh@best.com (Tom Holub)
#Newsgroups: best.general
#Subject: Re: Sorting a .newsrc
#Date: 20 Jan 1997 11:48:45 -0800
#Message-ID: <5c0i6t$639@shellx.best.com>
#Organization: BEST Internet Communications
#
#
#In article <5bv6ir$93n@shellx.best.com>,
# Leo L. Schwab <ewhac@best.com> wrote:
#)
#) This because of the way the ':' character compares with '.'.
#
#From the sort man page:
#
# -tx Use x as the field separator character; x is not considered to be
# part of a field (although it may be included in a sort key). Each
# occurrence of x is significant (for example, xx delimits an empty
# field). x may be a supplementary code set character. The default
# field separators are blank characters.
#
#So sort -t: should do it.
#
# -Tom
#
#==============================================================================
#
#From: ewhac@best.com (Leo L. Schwab)
#Newsgroups: best.general
#Subject: Re: Sorting a .newsrc
#Date: 21 Jan 1997 00:47:29 -0800
#Message-ID: <5c1vr1$5so@shellx.best.com>
#Organization: Verbatim Corp.: Abort, Retry, Ignore, Fail?
#
#
#In article <5c0i6t$639@shellx.best.com>, Tom Holub <doosh@best.com> wrote:
#>
#>So sort -t: should do it.
#
# Not quite. 'sort' needs to stop looking at either the ':' or the
#'!' character. 'sort' doesn't appear to allow more than one character as a
#field separator.
#
# I finally beat Perl into submission and got the desired result.
#Experienced Perl programmers will probably sneer at the result, and I
#wouldn't blame you:
#
#_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
#Leo L. Schwab -- Digital Spellweaver ewhac@best.com ..or..
# \_ -_ http://www.best.com/~ewhac/ ewhac@well.com
#O----^o Recumbent Bikes: The Only Way To Fly. (pronounced "EH-wack")
# Does J.R. "Bob" Dobbs shop for clothes at Fnordstrom?
#
#==============================================================================
#!/usr/local/bin/perl5
#
# usage: ngsort infile >outfile
sub ngsort {
my $aa = $a;
my $bb = $b;
my $retval;
if ($aa =~ /(.*?)[:!]/) {
$aa = $1;
}
if ($bb =~ /(.*?)[:!]/) {
$bb = $1;
}
@aa = split(/\./, $aa);
@bb = split(/\./, $bb);
while ($aa = shift(@aa), $bb = shift(@bb)) {
if ($retval = (lc($aa) cmp lc($bb))) {
return ($retval);
}
}
return ($aa cmp $bb);
}
print sort ngsort <>;
#---- snip --------------------------------------------------------------------
-----------------------------------------------------------------------------
Kim DeVaughn [ "All sweet things have one thing in common ... ]
kimdv@best.com /\oo/\ [ ... a tendency to make you sick." --Soolin ]
-----------------------------------------------------------------------------
Technical Details
Message-ID:
<6ttthb$rn5$1@nntp1.ba.best.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mailReferences:
<6ttnrf$d5d$1@ns2.intergrafix.net> <6ttop4$nld$1@news2.xs4all.nl>Show Full Headers
Complete Article Headers
Message-ID: <6ttthb$rn5$1@nntp1.ba.best.com> Subject: Re: How can I sort newsgroups? Date: Fri, 18 Sep 1998 00:00:00 +0000 From: kimdv@best.com (Kim DeVaughn) References: <6ttnrf$d5d$1@ns2.intergrafix.net> <6ttop4$nld$1@news2.xs4all.nl> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail X-Deja-AN: 392434079 Summary: then there's the right way ... X-Trace: 906131819 28389 kimdv 206.184.139.132 Organization: Kim's Home for Wayward Cocktail Waitresses & Hors d'oeuvre Girls Newsgroups: news.software.readers