check if there are files that need fixing
grep -R 'title: ".*".*"$' . | tee malformed-titles.txt
(util) strip stuff that grep -R
adds
cat malformed-titles.txt | sed 's/.*\.md://' |
(util) only keep filenames
cat malformed-titles.txt | sed 's/:.*//'
check that no existing files that would break -> this should be empty!
grep -R '/^title: [^"]*$' . | tee conflicting-lines.txt
(util) replace inline “make sure the previous check is empty!”
sed -i \
-e '/^title: ".*".*"$/s/"//g' \
-e '/^title: [^"]*$/s/title: \(.*\)/title: "\1"/'
- replace only where
title: " <has a double quote here> "
- remove all quotes
- find title: without quote
- add quotes at beginning and end of string title
create script with one command per file to fix using the previous sed command
cat malformed-titles.txt | sed 's/:.*//' | sed 's!^\(.*\)!sed -i .bak -e '"'"'/^title: ".*".*"$/s/"//g'"'"' -e '"'"'/^title: [^"]*$/s/title: \\(.*\\)/title: "\\1"/'"'"' "\1"! ' > fix.sh
run with
zsh fix.sh
speedrun
grep -R 'title: ".*".*"$' . | sed 's/:.*//' | sed 's!^\(.*\)!sed -i "" -e '"'"'/^title: ".*".*"$/s/"//g'"'"' -e '"'"'/^title: [^"]*$/s/title: \\(.*\\)/title: "\\1"/'"'"' "\1"! ' | zsh