From owner-freebsd-questions@FreeBSD.ORG Wed Dec 12 21:35:30 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6ED2616A417 for ; Wed, 12 Dec 2007 21:35:30 +0000 (UTC) (envelope-from bill@ayn.mi.celestial.com) Received: from ayn.mi.celestial.com (hayek.celestial.com [192.136.111.12]) by mx1.freebsd.org (Postfix) with ESMTP id 5B4E213C447 for ; Wed, 12 Dec 2007 21:35:30 +0000 (UTC) (envelope-from bill@ayn.mi.celestial.com) Received: from localhost (localhost [127.0.0.1]) by ayn.mi.celestial.com (Postfix) with ESMTP id A94286860065A; Wed, 12 Dec 2007 13:36:42 -0800 (PST) X-Virus-Scanned: amavisd-new at mi.celestial.com Received: from ayn.mi.celestial.com ([127.0.0.1]) by localhost (ayn.mi.celestial.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id PMFq8okatPsN; Wed, 12 Dec 2007 13:36:42 -0800 (PST) Received: by ayn.mi.celestial.com (Postfix, from userid 203) id 8ACB968600612; Wed, 12 Dec 2007 13:36:42 -0800 (PST) Date: Wed, 12 Dec 2007 13:36:42 -0800 From: Bill Campbell To: freebsd-questions@freebsd.org Message-ID: <20071212213642.GA9443@ayn.mi.celestial.com> Mail-Followup-To: freebsd-questions@freebsd.org References: <015f01c83d04$a1df2b20$dc96eed5@ihlasnetym> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <015f01c83d04$a1df2b20$dc96eed5@ihlasnetym> User-Agent: Mutt/1.5.11 OpenPKG/2.5 Subject: Re: How to use cut or awk commands into sed command ? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd@celestial.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Dec 2007 21:35:30 -0000 On Wed, Dec 12, 2007, Halid Faith wrote: >I have a file named file1 which contains some values. >I want to replace some strings into it, so I use sed command but I get an error. > >sed "s#oldstring#`cut -d, -f3 file2`#" file1 > >sed: 1: "s/yenidomain2/f0b2875d- ...": unterminated substitute in regular expression > >also I get an error with awk command into sed; >sed "s#oldstring#`awk -F, '{print$3}' file2`#" file1 >sed: 1: "s#yenidomain2#f0b2875d- ...": unterminated substitute in regular expression The ``cut -d...` may well be biting you with multiple lines or extra line feeds. You might see the problem by prefixing your command with ``echo'' to see what it's actually doing. echo sed "s#oldstring#`cut -d, -f3 file2`#" file1 I usually do more complex substitutions with short python or perl scripts as (a) they use a common regular expression syntax, and (b) I find the code cleaner (at least the python :-) Bill -- INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 Scientists are explorers. Philosophers are tourists. -- Richard Feynman