yq/pkg/yqlib/doc/Comment Operators.md

1.4 KiB

Use these comment operators to set or retrieve comments.

Set line comment

Given a sample.yml file of:

a: cat

then

yq eval '.a lineComment="single"' sample.yml

will output

a: cat # single

Set head comment

Given a sample.yml file of:

a: cat

then

yq eval '. headComment="single"' sample.yml

will output

# single

a: cat

Set foot comment, using an expression

Given a sample.yml file of:

a: cat

then

yq eval '. footComment=.a' sample.yml

will output

a: cat

# cat

Remove comment

Given a sample.yml file of:

a: cat # comment
b: dog # leave this

then

yq eval '.a lineComment=""' sample.yml

will output

a: cat
b: dog # leave this

Remove all comments

Given a sample.yml file of:

a: cat # comment

then

yq eval '.. comments=""' sample.yml

will output

a: cat

Get line comment

Given a sample.yml file of:

a: cat # meow

then

yq eval '.a | lineComment' sample.yml

will output

meow

Get head comment

Given a sample.yml file of:

a: cat # meow

then

yq eval '. | headComment' sample.yml

will output


Get foot comment

Given a sample.yml file of:

a: cat # meow

then

yq eval '. | footComment' sample.yml

will output