Como remover newlines de uma saída ip a s?

0

INPUT (comando "ip a s")

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether e3:1c:12:f3:5a:34 brd ff:ff:ff:ff:ff:ff
    inet 1.2.3.4/24 brd 1.2.3.255 scope global eth0
    inet6 fe80::e61f:13ff:fef3:5a34/64 scope link 
       valid_lft forever preferred_lft forever

OUTPUT:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether e3:1c:12:f3:5a:34 brd ff:ff:ff:ff:ff:ff inet 1.2.3.4/24 brd 1.2.3.255 scope global eth0 inet6 fe80::e61f:13ff:fef3:5a34/64 scope link valid_lft forever preferred_lft forever

Pergunta: como posso remover as novas linhas como INPUT / OUTPUT?

    
por somelooser28533 29.09.2014 / 10:54

3 respostas

0

solução feia antes do especialista em perl / sed

 ip a s| awk 'BEGIN { s=0 ; } /^[^\t ]/ {if (s>0) printf "\n" ; s++ ; } {printf " %s",$0;} END { printf "\n" ;}'

basicamente

 BEGIN { s=0 ; }

contador para linha

 /^[^\t ]/ {if (s>0) printf "\n" ; s++ ; }

se a linha começar com não em branco e não forst, emita uma nova linha

 {printf " %s",$0;}

copie a linha sem a nova linha

  END { printf "\n" ;}

no final, use uma nova linha.

    
por 29.09.2014 / 11:08
1

Você pode usar perl :

$ ip a s | perl -00pe 's/\n *(?![0-9])/ /g'
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host  valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether f4:6d:04:11:43:fc brd ff:ff:ff:ff:ff:ff
    
por 29.09.2014 / 11:04
1

Use a opção -o / -oneline . É exatamente isso que serve.

# ip -o addr show
1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever
1: lo    inet6 ::1/128 scope host \       valid_lft forever preferred_lft forever
4: wlan0    inet 192.168.0.24/24 brd 192.168.0.255 scope global wlan0\       valid_lft forever preferred_lft forever
4: wlan0    inet6 fe80::c685:8ff:fe80:dd06/64 scope link \       valid_lft forever preferred_lft forever
5: docker0    inet 172.17.42.1/16 scope global docker0\       valid_lft forever preferred_lft forever
5: docker0    inet6 fe80::5484:7aff:fefe:9799/64 scope link \       valid_lft forever preferred_lft forever
23: veth3d95    inet6 fe80::8429:16ff:fed6:beb3/64 scope link \       valid_lft forever preferred_lft forever
    
por 29.09.2014 / 15:02

Tags