我需要编写一个shell脚本,它将从显示的命令行输出中获取自定义结果。
考虑以下情况:
这是命令和相关输出。
id
现在我需要的是仅为具有以下值的名称字段获取id:
root@devstack:/opt/devstack# /usr/local/bin/neutron subnet-list
+--------------------------------------+---------------------+---------------------+-------------------------------------------------------------------------------+
| id | name | cidr | allocation_pools |
+--------------------------------------+---------------------+---------------------+-------------------------------------------------------------------------------+
| 3efe15d0-24a4-4618-8034-26345438da41 | private-subnet | 10.0.0.0/24 | {"start": "10.0.0.2", "end": "10.0.0.254"} |
| 4bf54b31-c14c-493b-92c1-079c65484113 | public-subnet | 172.24.4.0/24 | {"start": "172.24.4.2", "end": "172.24.4.254"} |
| 4fbe1ac2-ff40-4efa-8333-2c02be54312e | ipv6-private-subnet | fd6e:78a4:ae52::/64 | {"start": "fd6e:78a4:ae52::2", "end": "fd6e:78a4:ae52:0:ffff:ffff:ffff:ffff"} |
| 09b45af3-ef6f-4ad8-a4cb-643b218f0439 | ipv6-public-subnet | 2001:db8::/64 | {"start": "2001:db8::3", "end": "2001:db8::ffff:ffff:ffff:ffff"} |
| | | | {"start": "2001:db8::1", "end": "2001:db8::1"} |
+--------------------------------------+---------------------+---------------------+-------------------------------------------------------------------------------+
我已经尝试了如下命令,只获取没有指定条件的id:
private-subnet
public-subnet
有人让我知道只获得" id"其中名称具有值" private-subnet"和"公共子网"。
答案 0 :(得分:1)
我对neutron subnet-list命令提供的选项做了同样的工作。
我能够按预期获得所需的结果。
root@devstack:/opt/devstack# /usr/local/bin/neutron subnet-list --field id --name private-subnet
+--------------------------------------+
| id |
+--------------------------------------+
| 3efe15d0-24a4-4618-8034-26345438da41 |
+--------------------------------------+