yq
v4.x
v4.x
  • yq
  • How It Works
  • Recipes
  • Upgrading from V3
  • Commands
    • Evaluate
    • Evaluate All
    • Shell Completion
  • Operators
    • Add
    • Alternative (Default value)
    • Anchor and Alias Operators
    • Array to Map
    • Assign (Update)
    • Boolean Operators
    • Collect into Array
    • Column
    • Comment Operators
    • Compare Operators
    • Contains
    • Create, Collect into Object
    • Date Time
    • Delete
    • Divide
    • Document Index
    • Encode / Decode
    • Entries
    • Env Variable Operators
    • Equals
    • Eval
    • File Operators
    • Filter Operator
    • Flatten
    • Group By
    • Has
    • Keys
    • Kind
    • Length
    • Line
    • Load
    • Min
    • Map
    • Max
    • Modulo
    • Multiply (Merge)
    • Omit
    • Parent
    • Path
    • Pick
    • Pipe
    • Pivot
    • Recursive Descent (Glob)
    • Reduce
    • Reverse
    • Select
    • Shuffle
    • Slice Array
    • Sort
    • Sort Keys
    • Split into Documents
    • String Operators
    • Style
    • Subtract
    • Tag
    • To Number
    • Traverse (Read)
    • Union
    • Unique
    • Variable Operators
    • With
  • Usage
    • Output format
    • Working with CSV, TSV
    • Working with JSON
    • Working with Properties
    • Working with XML
    • Working with LUA
    • Working with TOML
    • Working with Shell Output
    • Front Matter
    • Split into multiple files
    • GitHub Action
    • Tips, Tricks, Troubleshooting
  • Github Page
Powered by GitBook
On this page
  • Process front matter
  • Extract front matter

Was this helpful?

  1. Usage

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.

Note that yq only processes the first passed in file for front-matter. If you'd like to process multiple files, you can:

find -name  "*.md" -exec yq --front-matter="process" '.updated_at = now' {} \;

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

yq --front-matter=process '.a="chocolate"' file.jekyll

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:

yq --front-matter=extract '.a="chocolate"' file.jekyll

Then this would yield:

---
a: chocolate
b: bannana
PreviousWorking with Shell OutputNextSplit into multiple files

Last updated 3 years ago

Was this helpful?