Date: Wed, 12 Dec 2007 13:36:42 -0800 From: Bill Campbell <freebsd@celestial.com> To: freebsd-questions@freebsd.org Subject: Re: How to use cut or awk commands into sed command ? Message-ID: <20071212213642.GA9443@ayn.mi.celestial.com> In-Reply-To: <015f01c83d04$a1df2b20$dc96eed5@ihlasnetym> References: <015f01c83d04$a1df2b20$dc96eed5@ihlasnetym>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071212213642.GA9443>
