From owner-freebsd-questions Mon Sep 24 6: 4:13 2001 Delivered-To: freebsd-questions@freebsd.org Received: from gahch.it.ca (gahch.it.ca [216.126.86.4]) by hub.freebsd.org (Postfix) with ESMTP id 99F9F37B418 for ; Mon, 24 Sep 2001 06:04:06 -0700 (PDT) Received: (from paul@localhost) by gahch.it.ca (8.11.6/8.11.6) id f8OD3gG11852; Mon, 24 Sep 2001 09:03:42 -0400 (EDT) (envelope-from paul) Date: Mon, 24 Sep 2001 09:03:42 -0400 From: Paul Chvostek To: Mark Rowlands Cc: freebsd-questions@FreeBSD.ORG Subject: Re: silly sed question Message-ID: <20010924090342.A10056@gahch.it.ca> References: <20010924115816.EE2F637B418@hub.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010924115816.EE2F637B418@hub.freebsd.org>; from mark.rowlands@minmail.net on Mon, Sep 24, 2001 at 01:58:12PM +0200 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hiya. On Mon, Sep 24, 2001 at 01:58:12PM +0200, Mark Rowlands wrote: > > I have a string > > TARGETS='blob1 blob2 blob3' > > and I wish to use to change this to > > TARGETS='blob1 blob2 blob3 blob4' > > for a multitude of files. > > I am having problems with the quotes > > sed -e '/^TARGETS s/'$/blob4'/' myfile > > ie find the line that begins with TARGETS and on that line swap the ending > single quote with blob4 and a single quote > > is what I want to write and for sed to DWIM..... > > I have tried escaping quotes in various places, double quotes and the like > but the correct incantation escapes me.......can anyone help Not silly at all. Escaping quotes is a black art. ;-) Assuming that any occurrance of /^TARGETS=/ would be fine to match, your original method could be grottily achieved like this: sed -e '/^TARGETS=/s/'"\'"'$/ blob4&/' myfile In a pinch, if the escaped quotes don't behave as expected, you can also refer to the single quotes with dots and backreferences, and maybe be more approximate with your matching. That is: sed -e '/^TARGETS=/s/\(.\)$/ blob4\1/' myfile -- Paul Chvostek Operations / Development / Abuse / Whatever vox: +1 416 598-0000 IT Canada http://www.it.ca/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message