From owner-freebsd-questions@FreeBSD.ORG Wed Feb 11 11:31:12 2009 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 331361065679 for ; Wed, 11 Feb 2009 11:31:12 +0000 (UTC) (envelope-from eculp@casasponti.net) Received: from ns2.bafirst.com (72-12-2-19.static.networktel.net [72.12.2.19]) by mx1.freebsd.org (Postfix) with ESMTP id DA6548FC08 for ; Wed, 11 Feb 2009 11:31:11 +0000 (UTC) (envelope-from eculp@casasponti.net) Received: from casasponti.net ([201.155.7.3]) by ns2.bafirst.com with esmtp; Wed, 11 Feb 2009 05:31:10 -0600 id 000D4CF3.4992B6FE.00002DCF Received: from localhost (localhost [127.0.0.1]) (uid 80) by casasponti.net with local; Wed, 11 Feb 2009 05:31:09 -0600 id 00130C59.4992B6FD.00006CAE Received: from dsl-189-129-4-168.prod-infinitum.com.mx (dsl-189-129-4-168.prod-infinitum.com.mx [189.129.4.168]) by intranet.casasponti.net (Horde Framework) with HTTP; Wed, 11 Feb 2009 05:31:09 -0600 Message-ID: <20090211053109.17qwm4xcvypwc4gww@intranet.casasponti.net> Date: Wed, 11 Feb 2009 05:31:09 -0600 From: eculp@casasponti.net To: freebsd-questions@freebsd.org References: <20090211213011.C38905@sola.nimnet.asn.au> In-Reply-To: <20090211213011.C38905@sola.nimnet.asn.au> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (5.0-cvs) X-Remote-Browser: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.0.5) Gecko/2009020709 Firefox/3.0.4, Ant.com Toolbar 1.2 X-IMP-Server: 201.155.7.3 X-Originating-IP: 189.129.4.168 X-Originating-User: eculp@casasponti.net Subject: Re: sh parameter substitution problem X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Feb 2009 11:31:12 -0000 Quoting Ian Smith : > I'm getting nowhere trying to parse out IP addresses from strings of > this form in /bin/sh, which have been awk'd out of 'tail named.run': > > addr='195.68.176.4#1440:' > addr='195.68.176.4#16811:' > addr='195.68.176.4#276:' > > sh(1) in hand, I've tried: > > ip=${addr:%#*} > ip=${addr:%%#*} > ip=${addr:%[#]*} > ip=${addr:%%[#]*} > > but all of these report './testbit: 7: Syntax error: Bad substitution' > > How can I split these strings to exclude the '#' and all beyond, > preferably using sh syntax, at least without resorting to perl? sed would work. Something like for i in addr='195.68.176.4#1440:' addr='195.68.176.4#16811:' addr='195.68.176.4#276:' do echo $i | sed 's/#.*//' done of course using the echo line in your script or something similar. I'm sure there are many simple or simpler solutions. ed > > Please cc me as I'm only subscribed to the digest. > > TIA, Ian > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > "Failure is the opportunity to begin again more intelligently." "Fracaso es la oportunidad de reiniciar con mas inteligencia" Henry Ford