Repository navigation
How can I avoid removing line breaks when updating a YAML file? #2700
Replies: 1 comment
|
yq is re-serializing the YAML, so the physical line break in a plain scalar is not preserved. In YAML, a line break inside a plain scalar is folded into a space, so: title: this is a long has the same value as: title: this is a long long title If you need the newline to be semantically preserved, use a literal block scalar instead: title: | yq supports controlling a node's YAML style with the style operator, e.g.: yq -i '.title style="literal" | .a = "two"' 1.yaml So if the requirement is to preserve the exact original formatting of an existing plain scalar while modifying another field, yq does not currently provide a general formatting-preservation mechanism for that case; using a round-tripping YAML tool would be more appropriate. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Running:
Results in:
Expected (preserving line break):
All reactions