Batch markdown edits anyone?

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!

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:

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

1 Like

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.

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.

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

1 Like

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

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

5 Likes

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

1 Like

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

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.

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:

The discussion continues on this other post: