How to use cut or awk commands into sed command ?

Bill Campbell freebsd at celestial.com
Wed Dec 12 13:35:30 PST 2007


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 at 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


More information about the freebsd-questions mailing list