On Tue, Oct 26, 2010 at 1:55 AM, Jack Schwartz <[email protected]> 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 1
>    inet 127.0.0.1 netmask ff000000
> e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500
> index 3
>    inet 10.132.145.68 netmask fffffe00 broadcast 10.132.145.255
> lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252
> index 1
>    inet6 ::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 IPv4
> e1000g0: 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}

I suspect google is finding references to other implementations of sed.

In this case the arguments inside the {} need to be newline separated.
Simplest way is to create a file containing

/BROADCAST.*IPv4/{n
p
}

and run

ifconfig -a | /usr/bin/sed  -n -f name_of_file

(Although on a system with multiple interfaces up I get multiple lines,
and on a system with zones I get the zone lines as well - I guess the
latter doesn't matter in this context, but with multiple interfaces I'm not
sure the ordering is well defined.)

-- 
-Peter Tribble
http://www.petertribble.co.uk/ - http://ptribble.blogspot.com/
_______________________________________________
caiman-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/caiman-discuss

Reply via email to