yq 处理带引号的字符串 [英] yq processing a string with quotation marks

查看:28
本文介绍了yq 处理带引号的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在尝试使用 mikefarah/yq<在 YAML 文件中交换一个字符串但带有双引号/a> 处理器(Ubuntu 机器上的 3.1.2 版)类似于以下内容:

Currently I am trying to exchange a string but WITH double quotes in a YAML file with the mikefarah/yq processor (version 3.1.2 on an Ubuntu machine) similar to the following:

config:
  app:
    name: "string"

所以我首先尝试为我经典地解决这个问题:

So I tried to solve this classically for me first with:

yq w -i appconfig.yml config.app.name "exchangedstring"

但是字符串中没有包含引号.

But the quotation marks were not included in the string.

config:
  app:
    name: exchangedstring

我曾多次尝试对字符串进行转义以获得所需的结果,但不幸的是,一切都不是所需的结果.例如,如果我将字符串设置为三重(类似于""),则设置了引号,但随后在它周围有一个单引号.它看起来像这样:

I have made several attempts to escape the string to get the desired result, but unfortunately everything was not the desired result. For example, if I set the string to triple (something like """), the quotation marks were set, but then there was a single quote around it. It then looked like this:

config:
  app:
    name: '"exchangedstring"'

但我想要的结果是这样的:

But my desired result would be like this:

config:
  app:
    name: "exchangedstring"

我还尝试使用不同变体的反斜杠(例如\"exchangedstring\"" 或 '\"exchangedstring\"').不幸的是所有错误的结果.我不排除后面解析yaml文件的应用程序不会乱位置的字符串的可能性,所以对我来说绝对有必要把位置的字符串放在引号中.

I also tried it with backslashes in different variations (example "\"exchangedstring\"" or '\"exchangedstring\"'). Unfortunately all the wrong result. I can't exclude the possibility that the application that will later parse the yaml file will not mess with the string at the position, so it is absolutely necessary for me that the string is in quotation marks at the position.

有谁知道我如何仍然只能得到一个简单版本的引号?预先非常感谢您.

Does anybody have an idea how I can still get only a simple version of quotation marks in place? Thank you very much in advance.

推荐答案

mikefarah 的最新版本(v3 以上)/yq 有一个 --style 选项 引入,它允许您对值进行自定义格式设置.例如您可以使用 --style=double 对值进行双引号

The latest release (v3 onwards) of mikefarah/yq has a --style option introduced which allows you to do custom formatting of the values. For e.g. you can use --style=double to double quote the value

yq w -i appconfig.yml config.app.name --style=double exchangedstring

这篇关于yq 处理带引号的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆