Neat little .newsrc fixer-upper.

David Elliott dce at mips.COM
Wed Apr 27 01:02:32 AEST 1988


In article <3931 at killer.UUCP> jfh at killer.UUCP (The Beach Bum) writes:
>Not only is this an inappropriate posting, it is an intentional posting.
>But hey, this turned out to be a real handy three minute hack.
>
>This little toy takes your (possibly uneditable) .newsrc and removes
>all the garbage between 1 and the last article you read.  i wrote it
>because my .newsrc on killer was in bad shape and couldn't be edited
>because some of the lines were too long.  this could be written much
>better, with a man page and all, but then it might get posted to a
>source group!

Why write a C program when a standard Unix utility can do the trick?

sed 's/^\([^:!]*[:!]\)[  ]\([0-9][0-9]*\)[-,][-,0-9]*[-,]\([0-9][0-9]*\)[    ]*$/\1 \2-\3/'

It's actually very easy when you understand the subexpressions:

^\([^:!]*[:!]\) 	is the newsgroup name, including the ! or :.
[  ]			(a space and a tab) is the whitespace separating the
			name of the newsgroup from the first article number
\([0-9][0-9]*\) 	is the number of the first article
[-,][-,0-9]*[-,]	describes all of the stuff between the first and
			last article numbers, whether it's ranges or lists
\([0-9][0-9]*\)		is the last article number
[  ]*$			is (optional) trailing whitespace and the end of the
			line

The \1 corresponds to the first set of things in \(\), \2 the second set,
and \3 the third.

-- 
David Elliott		dce at mips.com  or  {ames,prls,pyramid,decwrl}!mips!dce



More information about the Comp.unix.questions mailing list