Skip to content

Instantly share code, notes, and snippets.

@jsjoeio
Created July 3, 2020 04:02
Show Gist options
  • Save jsjoeio/044fa9dd43b4ddc68143b84941582612 to your computer and use it in GitHub Desktop.
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
# 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