Tag Mass Action: Add, Rename, and Delete a tag in multiple files (Tag Wrangler)

I really should have read the whole thread first to see the better solutions that had already been posted. But I wrote this bash script for my own use, and I might as well dump it here:

#!/bin/bash
set -e
FROM="#context-home"
TO="#home"

# Search for all .md or .MD files in the current working directory.
# For each, do the indicated replacement.
find . -type f -name "*.md" -o -name "*.MD" | while read file; do
    # If the file does not contain the FROM string, skip it.
    grep -q "$FROM" "$file" || continue
    echo "Processing $file"
    sed -i "s/$FROM/$TO/g" "$file"
done

(I should say, really, “Github Copilot and I wrote”. My bash/find/sed ability is weak enough that it would have taken me a good half an hour to look up the right usages on my own. AI, man.)

1 Like