Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我正在运行以下命令来提取我感兴趣的实例的信息:
新星名单 | grep derpInstance
我得到:
| 37696b22-1afa-40fa-81cc-241493ef09e1 | derpInstance | ACTIVE | None | Running | devcos-shared-net-10-9-254-0_24=10.9.254.129 |
我对 IP 地址(= 符号后面的东西)感兴趣,我如何在 shell 脚本中提取它?
谢谢!
或使用 sed:
nova list | grep derpInstance | sed 's/.*=//;s/ .*//'
请注意,像这样的解决方案通常很脆弱。如果您想要一个健壮的程序,您应该确保您了解字段的语法,以便简单的正则表达式不会在您之前未见过的字符出现在输出中时中断。例如,如果 = 符号可以出现在任何其他字段中,则该符号将中断。
试试这个:
nova list | grep derpInstance|grep -Po '(?<==)[0-9.]*'