yq工具处理yaml文件

1.yq介绍

一个轻量级、可移植的命令行 YAML、JSON 和 XML 处理器。yq使用类似jq 的语法,但可以处理 yaml 文件以及 json、xml、properties、csv 和 tsv。它还不支持所有jq功能 - 但它确实支持最常见的操作和功能,并且正在不断添加更多功能

 

2.github地址

https://github.com/mikefarah/yq/#install

 

3.yq命令下载

wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\
    chmod +x /usr/bin/yq

 

4.yaml文件

cv-platform:
  algcloud:
    host: 188.88.88.8

  picServer: 'http://188.88.88.8:29001/cm-platform/'

  oss:
    type: minio
    endpoint: "http://188.88.88.8:29001/"
    
  stream:
    to: 'rtmp://188.88.88.8'
    play: 'http://188.88.88.8'

 

5.单行处理

#!/bin/bash

ip=199.99.99.99
yq ".cv-platform.algcloud.host=\"$ip\"" -i cv-platfom-common.yaml
yq ".cv-platform.picServer=\"http://$ip:29001/cm-platform/\"" -i cv-platfom-common.yaml
yq ".cv-platform.oss.endpoint=\"http://$ip:29001/\"" -i cv-platfom-common.yaml
yq ".cv-platform.stream.to=\"rtmp://$ip\"" -i cv-platfom-common.yaml
yq ".cv-platform.stream.play=\"http://$ip\"" -i cv-platfom-common.yaml

 

6.多行处理

#!/bin/bash

ip=188.88.88.8
yq '.cv-platform.algcloud.host = "'"$ip"'" | 
    .cv-platform.picServer = "http://'"$ip"':29001/cm-platform/" | 
    .cv-platform.oss.endpoint = "http://'"$ip"':29001/" | 
    .cv-platform.stream.to = "rtmp://'"$ip"'" | 
    .cv-platform.stream.play = "http://'"$ip"'"' -i cv-platfom-common.yaml

 

7.参考文档

https://blog.csdn.net/pigoss02/article/details/124237216

 

其余命令可自行查看帮助。。。

 

posted @ 2024-05-14 11:25  Leonardo-li  阅读(131)  评论(0编辑  收藏  举报