y
y
yq
Search…
Front Matter
yq can process files with yaml front matter (e.g. jekyll, assemble and others) - this is done via the --front-matter/-f flag.

Process front matter

Use --front-matter=process to process the front matter, that is run the expression against the yaml content, and output back the entire file, included the non-yaml content block. For example:
File:
1
---
2
a: apple
3
b: bannana
4
---
5
<h1>I like {{a}} and {{b}} </h1>
Copied!
The running
1
yq e --front-matter=process '.a="chocolate"' file.jekyll
Copied!
Will yield:
1
---
2
a: chocolate
3
b: bannana
4
---
5
<h1>I like {{a}} and {{b}} </h1>
Copied!

Extract front matter

Running with --front-matter=extract will only output the yaml contents and ignore the rest. From the previous example, if you were to instead run:
1
yq e --front-matter=extract '.a="chocolate"' file.jekyll
Copied!
Then this would yield:
1
---
2
a: chocolate
3
b: bannana
Copied!
Last modified 29d ago