Created
July 3, 2020 04:02
-
-
Save jsjoeio/044fa9dd43b4ddc68143b84941582612 to your computer and use it in GitHub Desktop.
Migration script - rename files to kebab-lowercase and add a heading to the start
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loop over all markdown files | |
for file in *.md | |
do | |
# Remove the file extension | |
filename=${file%.*} | |
# Create new filename it by replacing spaces with - and lowercasing it | |
newFileName="`echo $file | sed s/\ /\-/g | tr 'A-Z' 'a-z'`" | |
# Rename file | |
mv "$file" "$newFileName" | |
# Capitalize the first letter for heading | |
heading="$(tr '[:lower:]' '[:upper:]' <<< ${filename:0:1})${filename:1}" | |
# Add heading to file | |
# echo "# $heading\n" >> $file | |
# Add heading to file | |
# TODO this part is not working | |
sed -i '' "# $heading\n" $newFileName | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment