The WolfspyreLabs Blog/ 2022/ July/ Bulk editing files on linux via the commandline/ 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…. The first few lines of one of the files ... ```shell ~/Git_Repos/Wolfspyre/docs/content (wpl_main)$ head -6 Snippits/Geekdocs/Shortcodes/aaa.md --- categories: ['Hugo',Tech] description: 'Create a Table of Content' type: 'docs' ``` 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. Contents of ed.script ... ##### ed.script 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. Contents of edscript.sh ...