[gnu.emacs.gnus] here is a .newsrc sorter/reorderer

chip@tct.uucp (Chip Salzenberg) (01/13/91)

This script sorts the ".newsrc" file in $HOME based on the order of
news hierarchies specified in the @H array near the top of the script.
It's not elegant, but I use it all the time.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  sortnewsrc
# Wrapped by chip@tct on Sat Jan 12 14:06:06 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'sortnewsrc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sortnewsrc'\"
else
echo shar: Extracting \"'sortnewsrc'\" \(968 characters\)
sed "s/^X//" >'sortnewsrc' <<'END_OF_FILE'
Xeval 'exec /bin/perl -S $0 ${1+"$@"}'
X	if 0;
X
X# $Id: sortnewsrc,v 1.1 90/10/03 11:19:37 news Exp $
X#
X# Sort a user's .newsrc file.
X#
X
X@H = ("general", "tct", "tba", "fl",
X      "news", "comp", "sci",
X      "alt", "gnu", "pubnet", "biz",
X      "misc", "rec", "soc", "talk");
X
X$x = "a";
Xforeach $h (@H) {
X	$X{$h} = $x;
X	++$x;
X}
X$X{"other"} = $x;
X
Xchdir $ENV{"HOME"} || die "can't change to home directory: $!\n";
X
Xopen(RC, ".newsrc") || die "can't open .newsrc: $!\n";
Xwhile (<RC>) {
X	chop;
X	next unless ($group) = /^([^:!]+)[:!]/;
X	($hier) = split(/\./, $group);
X	$x = $X{"other"} unless $x = $X{$hier};
X	push(@G, $x . "#" . $_);
X}
Xclose(RC);
X
X@G = sort @G;
X
Xopen(NRC, ">.newnewsrc") || die "can't create .newnewsrc: $!\n";
Xforeach $g (@G) {
X	($a, $b) = split(/#/, $g);
X	print NRC $b, "\n";
X}
Xclose(NRC);
X
Xunlink(".oldnewsrc");
Xrename(".newsrc", ".oldnewsrc") || die "can't rename .newsrc: $!\n";
Xrename(".newnewsrc", ".newsrc") || die "can't rename .newnewsrc: $!\n";
END_OF_FILE
if test 968 -ne `wc -c <'sortnewsrc'`; then
    echo shar: \"'sortnewsrc'\" unpacked with wrong size!
fi
chmod +x 'sortnewsrc'
# end of 'sortnewsrc'
fi
echo shar: End of shell archive.
exit 0
-- 
Chip Salzenberg at Teltronics/TCT     <chip@tct.uucp>, <uunet!pdn!tct!chip>
       "If Usenet exists, then what is its mailing address?"  -- me
             "c/o The Daily Planet, Metropolis."  -- Jeff Daiell