Date: Wed, 12 Mar 2003 11:17:02 +0100 From: Dean Strik <dean@stack.nl> To: Dean Strik <dean@stack.nl> Cc: Kok Kok <cckok002000@yahoo.ca>, freebsd-questions@FreeBSD.ORG Subject: Re: sed to replace the words Message-ID: <20030312101702.GC27853@dragon.stack.nl> In-Reply-To: <20030312101029.GB27853@dragon.stack.nl> References: <20030312061655.26510.qmail@web13305.mail.yahoo.com> <20030312101029.GB27853@dragon.stack.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
Dean Strik wrote: > Kok Kok wrote: > > Hi all > > > > I have question how to replace words using sed > > > > ./script 61.100 192.168 > > > > The script is > > #!/bin/sh > > sed -e 's/$2/$1/g' file > newfile > > > > The problem is 192.168 can't replace 61.100 in the > > newfile > > The single quotes prevent interpolation, the $... are not treated as > variables by the shell. Use double quotes instead: > > sed -e "s/$2/$1/g" file > newfile Sidenote: ./script 61.100 192.168 replaces 192.168 by 61.00, which seems to be the opposite of what you want, so change positions of $1 and $2 if necessary. -- Dean C. Strik Eindhoven University of Technology dean@stack.nl | dean@ipnet6.org | http://www.ipnet6.org/ "This isn't right. This isn't even wrong." -- Wolfgang Pauli To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030312101702.GC27853>