shell - 如何grep一个yaml值
问题描述
我尝试从 shell 中的 YAML 文件中获取值:
apiVersion: v1
items:
- apiVersion: v1
kind: Pod
spec:
containers:
hostIP: 12.198.110.192
phase: Running
podIP: 10.244.1.9
我得到kubectl get pods -l run=hello-kube -o yaml | grep podIP:
这个输出:
podIP: 10.244.1.9
我的目标是将该值保存在环境变量中,但我只得到key/value
-pair:
export PODIP=$(kubectl get pods -l run=hello-kube -o yaml | grep podIP)
解决方案
使用 awk:
kubectl get pods -l run=hello-kube -o yaml | awk '/podIP:/ {print $2}'
输出:
10.244.1.9
推荐阅读
- visual-studio-2019 - 为什么当我调用函数时,作为 Eigen::Matrx 函数输入的地址会改变?
- python - 如何在python中生成所有具有固定长度的四位数字的序列号?
- azure-storage - 仅当 Blob 完全提交时才发生 BlobCreated 事件
- r - 基于多列重塑数据集
- rest - 无法使用标头感染 api
- three.js - Three.js 网格的天使调整
- java - 调用 onBackPressed ViewGroup 后不可见
- pine-script - 为今天和昨天扩展框
- spring-boot - Spring Boot 管理员兼容性 Spring Boot 版本和日志记录实例
- spring - 如果抛出运行时异常,然后在用spring的@Transactional注解的方法中捕获,导致事务回滚?