比如执行如下命令后会有一长串字符串,想从中提取IP地址
# neutron port-list| grep oam:vip
| d277b883-3cb7-4844-9143-6705e1c5e4f5 | VSTACK-network:oam:vip:0-0-1:0-0-9 | fa:16:3e:54:62:29 | {"subnet_id": "58d1e6ce-ff86-4eeb-b22e-f5e2558146ae", "ip_address": "192.168.1.180"} |
通过sed 's/.*ip_address": "\(.*\)".*/\1/g'匹配IP地址并进行输出
# neutron port-list| grep oam:vip| sed 's/.*ip_address": "\(.*\)".*/\1/g'
192.168.1.180
sed输出指定行:
sed ‘/pattern/!p’ infile //匹配pattern的行不输出
sed -n ‘1,2p’ infile //print line 1 to 2
sed -n ‘2,$p’ file //print line 2 to end of line