Mac: Regular expression to parse scutil command output I've below output from scutil --nc show &lt;service id&gt;

Connected
Extended Status &lt;dictionary&gt; {
  ConnectionStatistics : &lt;dictionary&gt; {
    ConnectCount : 6
    ConnectedCount : 3
    DisconnectedCount : 5
    MaxConnectTime : 1874
  }
  IPv4 : &lt;dictionary&gt; {
    Addresses : &lt;array&gt; {
      0 : 10.20.15.181
    }
    ExcludedRoutes : &lt;array&gt; {
      0 : &lt;dictionary&gt; {
        DestinationAddress : 115.112.149.120
        InterfaceName : en0
        SubnetMask : 255.255.255.255
      }
      1 : &lt;dictionary&gt; {
        DestinationAddress : 115.112.149.120
        InterfaceName : en0
        SubnetMask : 255.255.255.255
      }
      2 : &lt;dictionary&gt; {
        DestinationAddress : 115.112.149.120
        InterfaceName : en0
        SubnetMask : 255.255.255.255
      }
      3 : &lt;dictionary&gt; {
        DestinationAddress : 115.112.149.120
        InterfaceName : en0
        SubnetMask : 255.255.255.255
      }
      4 : &lt;dictionary&gt; {
        DestinationAddress : 115.112.149.120
        InterfaceName : en0
        SubnetMask : 255.255.255.255


I wanted to take out ip addresses from Addresses : &lt;array&gt; from below

IPv4 : &lt;dictionary&gt; {
    Addresses : &lt;array&gt; {
      0 : 10.20.15.181
      1 : 10.20.15.182
    }


How to write regular expression for it?
You could try something like this:

scutil --nc show &lt;service id&gt; | sed -n '/IPv4/,/ExcludedRoutes/p' | sed '/ExcludedRoutes/,/{/d'



sed -n '/IPv4/,/ExcludedRoutes/p' will show text between IPv4 and ExcludedRoutes, both included.
sed '/ExcludedRoutes/,/{/d' will remove the ExcludedRoutes line.


The result will be like this:

$ cat file &lt;replace-with-your-command&gt; | sed -n '/IPv4/,/ExcludedRoutes/p' | sed '/ExcludedRoutes/,/{/d'
  IPv4 : &lt;dictionary&gt; {
    Addresses : &lt;array&gt; {
      0 : 10.20.15.181
    }