yq processing a string with quotation marks

戏子无情 提交于 2021-01-27 06:49:33

问题


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"

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.


回答1:


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


来源:https://stackoverflow.com/questions/62198943/yq-processing-a-string-with-quotation-marks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!