Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-tgr!tgr!bilbo.niket@locus.ucla.edu From: bilbo.niket@locus.ucla.edu (Niket K. Patwardhan) Newsgroups: net.unix Subject: Re: INFO-UNIX Digest V2#006 Message-ID: <3492@brl-tgr.ARPA> Date: Fri, 22-Nov-85 12:49:58 EST Article-I.D.: brl-tgr.3492 Posted: Fri Nov 22 12:49:58 1985 Date-Received: Sun, 24-Nov-85 06:47:59 EST Sender: news@brl-tgr.ARPA Lines: 29 The pattern matching allows you to break up the pattern into parts and replace specific bits of it in the substitute command. Try this (you may have to escape stuff if this is on the sed command line) s/\(#{garbage}\)#/\1/ What this does is bracket the first part of the pattern so you can refer to it later: (the \(\) does this). Then when you are doing the replacement you ask for only the first part rather than the whole thing: ( \1 rather than &). If you have multiple pieces you bracket the pieces you want to refer to, and you refer to the pieces by counting the number of \( starting from the left. Eg. s/ \(\(xyz\)abc\(pqr\)\) / \1\2\3/ on xyzabcpqrxxx results in xyzabcpqrxyzpqrxxx \1 is xyzabcpqr \2 is xyz \3 is pqr If the trailing # is at the end of the line just use s/#$// Good luck!