Skip to content

How to remove whitespace around the = when converting from yaml to props and change the . to any desired character? #1297

Answered by mikefarah
saurin-tech asked this question in Q&A
Discussion options

You must be logged in to vote

The properties encoder I'm using automatically puts the space around the equals sign - and there is no way to control that. According to the properties spec however, this whitespace is ignored (https://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s0204propertiesfileformat01.html).

That said, you can use an expression to generate your own format, including the '_' instead of '.':

yq '..  | select(tag != "!!map" and tag != "!!seq") | 
  ( (path | join("_")) + "=" + .)
' input.yaml

Explanation:

  • .. | select(tag != "!!map" and tag != "!!seq") find all the nodes that are scalars (not maps or arrays)
  • ( (path | join("_")) + "=" + .) grab the path array of the node, join with "_", a…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@saurin-tech
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by saurin-tech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants