Matthew Adams
Matthew Adams

Reputation: 2197

How do I use `yq` to count the number of yaml documents present in multidocument yaml file that uses the `---` separator?

Given yaml file:

---
one: hey
---
two: you
---

How do I use yq to count the number of distinct yaml documents in the file?

yq ea '. as $item ireduce (0; . + 1)'

yields

3
3
3

and

yq e '. as $item ireduce (0; . + 1)'

yields

1
1
1

Not only can I not get the syntax quite right, I argue that, since the first three characters in the yaml file are --- and the last three are ---, my expectation is that there should only be two documents.

Upvotes: 1

Views: 413

Answers (0)

Related Questions