Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Feb 2009 05:31:09 -0600
From:      eculp@casasponti.net
To:        freebsd-questions@freebsd.org
Subject:   Re: sh parameter substitution problem
Message-ID:  <20090211053109.17qwm4xcvypwc4gww@intranet.casasponti.net>
In-Reply-To: <20090211213011.C38905@sola.nimnet.asn.au>
References:  <20090211213011.C38905@sola.nimnet.asn.au>

next in thread | previous in thread | raw e-mail | index | archive | help
Quoting Ian Smith <smithi@nimnet.asn.au>:

> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090211053109.17qwm4xcvypwc4gww>