Skip to main content
  1. 2022/
  2. July/

Bulk editing files on linux via the commandline

What are we trying to do? #

I realized the metadata of the various files here was a little rough around the edges. That inconsistency was making it hard to have automation behave properly.

This meant I have hundreds of files which each needed just a little something different done to them.

for example, we have a list of a few files here:

docs/WPL/servers.md
docs/Observium/data.md
docs/Smallstep/setup.md
docs/Raspbian/PXE/make-it-go.md

in each of those files, we want to inject some data into the hugoFrontmatter of the page:

kind: 'page'

We want to do this Anywhere after the first line….

But before the second set of --- characters, which signifies the end of Frontmatter to Hugo

What tools we have handy #

Caveats…. There’s always some bullshit isn’t there? #

Because we want to add a line that has a space, a colon, and single quotes, things get a LITTLE wonky.

not a big deal, but it does make it slightly more awkward toolchain wise…. and that makes it harder to avoid making a mistake.

so… back to The Unix Philosophy of stringing a bunch of single purpose tools together to make it go it is!

Lets do it! #

Using ed #

the old and trusty ed really comes to the rescue in times like this.

so… cool…

  • We have a list of files which need the alteration: foo.txt.

  • We have a script to drive ed

Now we need to coalesce some tooling to do the needful.