Mac: Scutil komut çıktısını ayrıştırmak için normal ifade


0

Çıkışının altındayım scutil --nc show <service id>

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

IP adreslerini Addresses : <array>aşağıdan çıkarmak istedim

IPv4 : <dictionary> {
    Addresses : <array> {
      0 : 10.20.15.181
      1 : 10.20.15.182
    }

Bunun için düzenli ifade nasıl yazılır?

Yanıtlar:


3

Böyle bir şeyi deneyebilirsin:

scutil --nc show <service id> | sed -n '/IPv4/,/ExcludedRoutes/p' | sed '/ExcludedRoutes/,/{/d'
  • sed -n '/IPv4/,/ExcludedRoutes/p'her ikisi de dahil olmak üzere IPv4ve arasındaki metni gösterir ExcludedRoutes.
  • sed '/ExcludedRoutes/,/{/d'ExcludedRoutesçizgiyi kaldıracak .

Sonuç şöyle olacak:

$ cat file <replace-with-your-command> | sed -n '/IPv4/,/ExcludedRoutes/p' | sed '/ExcludedRoutes/,/{/d'
  IPv4 : <dictionary> {
    Addresses : <array> {
      0 : 10.20.15.181
    }
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.