From owner-freebsd-questions Wed Mar 12 2:17: 6 2003 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4B4D037B401 for ; Wed, 12 Mar 2003 02:17:05 -0800 (PST) Received: from hexagon.stack.nl (hexagon.stack.nl [131.155.140.144]) by mx1.FreeBSD.org (Postfix) with ESMTP id C95B843FDD for ; Wed, 12 Mar 2003 02:17:03 -0800 (PST) (envelope-from dean@dragon.stack.nl) Received: by hexagon.stack.nl (Postfix, from userid 65534) id D8DFA1C3A; Wed, 12 Mar 2003 11:17:02 +0100 (CET) Received: from dragon.stack.nl (dragon.stack.nl [2001:610:1108:5011:207:e9ff:fe09:230]) by hexagon.stack.nl (Postfix) with ESMTP id 42B821C2C; Wed, 12 Mar 2003 11:17:02 +0100 (CET) Received: by dragon.stack.nl (Postfix, from userid 1600) id 2FEF75F174; Wed, 12 Mar 2003 11:17:02 +0100 (CET) Date: Wed, 12 Mar 2003 11:17:02 +0100 From: Dean Strik To: Dean Strik Cc: Kok Kok , freebsd-questions@FreeBSD.ORG Subject: Re: sed to replace the words Message-ID: <20030312101702.GC27853@dragon.stack.nl> References: <20030312061655.26510.qmail@web13305.mail.yahoo.com> <20030312101029.GB27853@dragon.stack.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030312101029.GB27853@dragon.stack.nl> X-Editor: VIM Rulez! http://www.vim.org/ X-MUD: Outerspace - telnet://mud.stack.nl:3333 X-Really: Yes User-Agent: Mutt/1.5.3i X-Spam-Status: No, hits=-32.8 required=5.0 tests=EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_MUTT version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) 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 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