Un-garbled:
ifconfig -a | sed -n '/BROADCAST.*IPv4/ {n;p;}'
If you specify all "up" IPv4 interfaces in the user's zone,
you could then use:
ifconfig -au4Z | sed -n -e'/127.0.0.1/d' -e '/inet/{p;q;}
--
Oracle <http://www.oracle.com>
Randall Chuck | Internal Customer Technical Engineer
Phone: +1 408 276-7585
Oracle Hardware Compute Resources | Lab Technologies
4160 Network Circle | Santa Clara, CA 95054 USA
Green Oracle <http://www.oracle.com/commitment> Oracle is committed to
developing practices and products that help protect the environment
On 10/25/10 17:55, Jack Schwartz wrote:
Hi everyone. I'm trying to do a sed one-liner but can't seem to get it to work...I want to parse ifconfig -a output and print the line which follows the line with the regular expression of "BROADCAST.*IPv4". End goal is to get the IP Address and netmask of the first non-loopback IPv4 interface.So when I see this: ---lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1inet 127.0.0.1 netmask ff000000e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 3inet 10.132.145.68 netmask fffffe00 broadcast 10.132.145.255lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1inet6 ::1/128 e1000g0: flags=20002004841<UP,RUNNING,MULTICAST,DHCP,IPv6> mtu 1500 index 3 inet6 fe80::223:18ff:fe72:3644/10 schwa...@jslaptop:~/test$ ifconfig -a | grep BROADCAST | grep IPv4e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 3--- I want to output this: inet 10.132.145.68 netmask fffffe00 broadcast 10.132.145.255 Everywhere I google I see that the following should work: ifconfig -a | /usr/bin/sed -n '/BROADCAST.*IPv4/{n;p}' but I get an error with /usr/bin/sed instead: sed: command garbled: /BROADCAST.*IPv4/{n;p} More confusing to me is when I remove the {} I get too much output:lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1inet 127.0.0.1 netmask ff000000 inet 10.132.145.68 netmask fffffe00 broadcast 10.132.145.255lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1inet6 ::1/128 e1000g0: flags=20002004841<UP,RUNNING,MULTICAST,DHCP,IPv6> mtu 1500 index 3 inet6 fe80::223:18ff:fe72:3644/10 (actually, this is all the lines except the one I am searching for) When I run gnu sed, then it works. ifconfig -a | /usr/gnu/bin/sed -n '/BROADCAST.*IPv4/ {n;p}' inet 10.132.145.68 netmask fffffe00 broadcast 10.132.145.255 Questions:1) Is using gnu sed a problem if this code is for an auto-installer project? 2) What am I doing incorrectly above? How do I "un-garble" the /usr/bin/sed command?Thanks, Jack _______________________________________________ caiman-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/caiman-discuss
<<attachment: Randall_Chuck.vcf>>
_______________________________________________ caiman-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/caiman-discuss

