# Batch markdown edits anyone?

**URL:** <https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615>\
**Category:** support\
**Created:** [August 15, 2018, 9:20pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615 "2018-08-15T21:20:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [August 15, 2018, 9:20pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/1 "2018-08-15T21:20:45Z")

</div>

Hello there,

I often find myself with hundreds of markdown files which would benefit from a new Front Matter key/value pair.

Yet doing such Front Matter batch editing is rather complicated for someone uneducated about bash or shell script (the usage of those two words may give you a hint on my knowledge in the matter).

I’m wondering if any one know about documentations or posts or some command line tool which allow convenient batch editing of markdown files.

Thanks a ton!

---

<div class="post-metadata">

**Author:** ![RickCogley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rickcogley/32/10269_2.png) [@RickCogley](https://discourse.gohugo.io/u/RickCogley)\
**Post date:** [August 15, 2018, 9:26pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/2 "2018-08-15T21:26:27Z")

</div>

I usually end up using bulk search and replace in whatever editor I’m using. Most allow a regex to be specified in the “find” part, to target frontmatter. You can also use things like `sed` or `awk` if you want to go the bash script route.

An example:

> <https://gist.github.com/arthurattwell/4219720913b8c0066e65eb300fc31790>

Complex, yes, but Regexes are worth learning because you can use them in so many contexts.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [August 15, 2018, 9:29pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/3 "2018-08-15T21:29:30Z")

</div>

I once had (and probably still do) a GUI based tools to do mass edits of this type – and it was pretty good. But I forgot what …

That said, Sublime 3 is also pretty good at this with regexps.

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [August 15, 2018, 9:34pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/4 "2018-08-15T21:34:29Z")

</div>

I’m not regexp genius, so I’m stuck with find and replace it’s not easy this way to only add one last key value at the end of the front matter section.

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [August 15, 2018, 10:17pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/5 "2018-08-15T22:17:09Z")

</div>

Thanks @RickCogley! I’ll closely look at your gist!

---

<div class="post-metadata">

**Author:** ![budparr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/budparr/32/749_2.png) [@budparr](https://discourse.gohugo.io/u/budparr)\
**Post date:** [August 15, 2018, 11:37pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/6 "2018-08-15T23:37:34Z")

</div>

@regis this site will help you become (or feel like, for a moment) a regex genius: [https://regexr.com/](https://regexr.com/)

Also, Chris has a tool that might be helpful (I haven’t used it) [https://github.com/chrisdmacrae/front-matter-manipulator](https://github.com/chrisdmacrae/front-matter-manipulator)

---

<div class="post-metadata">

**Author:** ![budparr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/budparr/32/749_2.png) [@budparr](https://discourse.gohugo.io/u/budparr)\
**Post date:** [August 15, 2018, 11:40pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/7 "2018-08-15T23:40:35Z")

</div>

Also, the automator app on a mac is helpful for setting up file operations that you can save and re-use.

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [August 15, 2018, 11:42pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/8 "2018-08-15T23:42:49Z")

</div>

Thanks @budparr Chris’ tool might very well be what I’ve been looking for! I’ll try it out tomorrow!

---

<div class="post-metadata">

**Author:** ![RickCogley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rickcogley/32/10269_2.png) [@RickCogley](https://discourse.gohugo.io/u/RickCogley)\
**Post date:** [August 16, 2018, 6:54am UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/9 "2018-08-16T06:54:26Z")

</div>

Not mine per se, just something I found that demonstrates how to pinpoint in frontmatter.  
Regex is worth the time it takes to study them. They are super complex, enough to make your head hurt especially at first, but they are used in _so_ many contexts in programming.

Google “regex tester” and you’ll find a bunch of good sites to test your regexes against.

---

<div class="post-metadata">

**Author:** ![jhabdas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jhabdas/32/6579_2.png) [@jhabdas](https://discourse.gohugo.io/u/jhabdas)\
**Post date:** [August 16, 2018, 5:20pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/10 "2018-08-16T17:20:31Z")

</div>

That looks useful. Based on the package manifest looks like the “manipulator” works with both YAML and TOML frontmatter. Not sure it would be any easier to use though than spending a little time doing a Find All /Replace from an editor (with or without regular expressions).

If the need to package up YAML frontmatter as a JSON blob (lodash anyone?) arises I just found:

> **[dworthen/js-yaml-front-matter](https://github.com/dworthen/js-yaml-front-matter)**
>
> Parses yaml or json from the beginning of a string or file - dworthen/js-yaml-front-matter

---

<div class="post-metadata">

**Author:** ![iaeiou](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/iaeiou/32/15332_2.png) [@iaeiou](https://discourse.gohugo.io/u/iaeiou)\
**Post date:** [August 18, 2022, 7:55pm UTC](https://discourse.gohugo.io/t/batch-markdown-edits-anyone/13615/11 "2022-08-18T19:55:10Z")

</div>

The discussion continues on this other post:

> [@How to edit the YAML Front Matter of multiple markdown files](https://discourse.gohugo.io/t/how-to-edit-the-yaml-front-matter-of-multiple-markdown-files/40070):
>
> Hi there, I’m migrating to a new theme, and needed to modify some Front matter variables in my posts. I’m lazy and I don’t like Regex, so I searched for a tool to help me. I found [yq](https://github.com/mikefarah/yq), a standalone CLI processor written in Go The [official documentation](https://mikefarah.gitbook.io/yq/) is pretty unclear, so I wrote a post: (I’m rebuilding the design of this site, things can be broken)
