2021-10-30 03:14:39 +00:00
# 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.
2022-04-14 22:52:46 +00:00
Note that `yq` only processes the first passed in file for front-matter. If you'd like to process multiple files, you can:
```bash
find -name "*.md" -exec yq --front-matter="process" '.updated_at = now' {} \;
```
2021-10-30 03:14:39 +00:00
## 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:
```
---
a: apple
b: bannana
---
< h1 > I like {{a}} and {{b}} < / h1 >
```
The running
```
2022-01-28 01:50:13 +00:00
yq --front-matter=process '.a="chocolate"' file.jekyll
2021-10-30 03:14:39 +00:00
```
Will yield:
```
---
a: chocolate
b: bannana
---
< h1 > I like {{a}} and {{b}} < / h1 >
```
## 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:
```
2022-01-28 01:50:13 +00:00
yq --front-matter=extract '.a="chocolate"' file.jekyll
2021-10-30 03:14:39 +00:00
```
Then this would yield:
```
---
a: chocolate
b: bannana
```