Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!mordor!sri-spam!ames!amdahl!pyramid!prls!mips!dce From: dce@mips.COM (David Elliott) Newsgroups: comp.unix.questions Subject: Re: Neat little .newsrc fixer-upper. Message-ID: <2083@quacky.mips.COM> Date: 26 Apr 88 15:02:32 GMT References: <3931@killer.UUCP> Reply-To: dce@quacky.UUCP (David Elliott) Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 31 In article <3931@killer.UUCP> jfh@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@mips.com or {ames,prls,pyramid,decwrl}!mips!dce