---
# System prepended metadata

title: Bash pipeline usage examples
tags: [linux, virsh, bash]

---

# Bash pipeline usage examples

###### tags: `linux` `bash` `virsh`

### list address/link/route in all network namespaces
```
ip netns | cut -d' ' -f1 | xargs -L1 -I {} sh -c "echo {}; ip netns exec {} ip -br -4 a | sed 's/^/  /g'; echo"
ip netns | cut -d' ' -f1 | xargs -L1 -I {} sh -c "echo {}; ip netns exec {} ip -br -4 a | sed 's/^/  /g' | awk '{print \$1,\$3}'; echo"
ip netns | cut -d' ' -f1 | xargs -L1 -I {} sh -c "echo {}; ip netns exec {} ip -br l | sed 's/^/  /g'; echo"
ip netns | cut -d' ' -f1 | xargs -L1 -I {} sh -c "echo {}; ip netns exec {} ip -br l | awk '{print \$1,\$3}' | sed 's/^/ /g'; echo"
ip netns | cut -d' ' -f1 | xargs -L1 -I {} sh -c "echo {}; ip netns exec {} ip r | sed 's/^/  /g'; echo"
```

### linux bridge
```
brctl show | tail -n +2 | sed -e 's/^\t\t\t*/,/g' -e 's/\t/ /g' | awk '{print $1,$4}' | sed -z -e 's/\n,/,/g' -e 's/ ,/,/g'
```

### virsh
```
virsh dumpxml <instance_name> | grep "dev='vnet\|dev='tap" | cut -d"'" -f2
virsh dumpxml <instance_name> | grep -B2 "dev='vnet\|dev='tap" | grep "mac address\|target dev" | cut -d"'" -f2 | sed 'N;s/\n/ /'
virsh dumpxml <instance_name> | grep -B3 -A4 "dev='vnet\|dev='tap" | grep "mac address\|target dev\|alias name" | cut -d"'" -f2 | sed 'N;N;s/\n/ /g'

# examples
root@nuc:/home/ycheng# virsh list | grep "running" | awk '{print $2}' | xargs -L1 -I {} sh -c "echo {}; virsh dumpxml {} | grep \"dev='vnet\|dev='tap\" | cut -d\"'\" -f2 | sed 's/^/  /g'"
firewall
  vnet0
  vnet1
firewall_2
  vnet2

root@nuc:/home/ycheng# virsh list | grep "running" | awk '{print $2}' | xargs -L1 -I {} sh -c "echo {}; virsh dumpxml {} | grep -B2 \"dev='vnet\|dev='tap\" | grep \"mac address\|target dev\" | cut -d\"'\" -f2 | sed 'N;s/\n/ /' | sed 's/^/  /g'"
firewall
  52:54:00:85:66:da vnet0
  52:54:00:38:46:8b vnet1
firewall_2
  52:54:00:c2:d7:ef vnet2
```