Article View: news.software.readers
Article #70997Re: Sorting .newsrc in Unix shell accoutn
From: Kim DeVaughn
Date: Tue, 23 Jan 2001 09:55
Date: Tue, 23 Jan 2001 09:55
179 lines
7203 bytes
7203 bytes
In article <3a6791fd$0$1517$53a6afc1@news.erinet.com>,
<president@whitehouse.gov> wrote:
|
| This might be seem like a stupid question, but is it possible to sort the
| .newsrc file in a shell account? I use tin for a newsreader and it's a pain
| sometime to look through all the groups available to me.
|
| Is the order of the groups important in .newsrc as long as each line remains
| intact? If I can't sort it within the shell, do you have any suggestions on
| how I might sort it in Win98?
Using sort(1) as others have suggested will work, but will result in
ordering like:
alt.foo.bar: 1-666
alt.foo: 1-12345
whereas most people would expect:
alt.foo: 1-12345
alt.foo.bar: 1-666
and the like, to be the more "correct" sequence.
I've been using the attached perl5 script for several years without any
problems, which solves the above type of collating sequence problem.
It's a "brute force" solution (ie, cpu intensive) , which may well have
more "elegant" implementations, but I've never been motivated enough to
try and develop one.
Note that caps (which newsgroup creators shouldn't use ... but some twits
do) and lower case collate the same, so if your .newsrc has groups that
use caps, you may want to do something like:
sort .newsrc | ngsort > sorted_newsrc && mv sorted_newsrc .newsrc
for the sake of consistency when new newsgroups are added (which may
contain caps) ...
Anyhow, thanks go to Leo Schawb (aka "Bols Ewacs") for this ...
/kim
PS: Put the perl5 script in your bin dir with the name "ngsort", and be
sure to chmod it to executable (eg, "chmod 0755 ngsort").
=========================================================================
"The number of arguments is unimportant unless some of them are correct."
--Ralph Hartley
-------------------------------------------------------------------------------
#!/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 <>;
##--EOF--##
Technical Details
Message-ID:
<94jkef$omn$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!supernews.google.com!sn-xit-02!sn-xit-04!supernews.com!europa.netcrusader.net!207.172.3.44!feed2.news.rcn.net!rcn!news2.best.com!nntp1.ba.best.com!not-for-mailReferences:
<3a6791fd$0$1517$53a6afc1@news.erinet.com>Show Full Headers
Complete Article Headers
Message-ID: <94jkef$omn$1@nntp1.ba.best.com> Subject: Re: Sorting .newsrc in Unix shell accoutn Date: Tue, 23 Jan 2001 09:55:27 +0000 From: kimdv@best.com (Kim DeVaughn) References: <3a6791fd$0$1517$53a6afc1@news.erinet.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!supernews.google.com!sn-xit-02!sn-xit-04!supernews.com!europa.netcrusader.net!207.172.3.44!feed2.news.rcn.net!rcn!news2.best.com!nntp1.ba.best.com!not-for-mail Newsgroups: news.software.readers Organization: Kim's Home for Wayward Cocktail Waitresses & Hors d'oeuvre Girls Lines: 178 NNTP-Posting-Host: shell3.ba.best.com X-Trace: nntp1.ba.best.com 980243727 25303 206.184.139.134 (23 Jan 2001 09:55:27 GMT) X-Complaints-To: abuse@best.com NNTP-Posting-Date: 23 Jan 2001 09:55:27 GMT Summary: a better solution ... X-Newsreader: trn 4.0-test72+ked.01 (05 September 1999)