How to trim trailing whitespace in a directory of Markdown files
If you have a directory full of Markdown files and want to remove trailing whitespace from each line in those files, you can use the following shell command. This command uses find
to locate all .md
files and sed
to edit them in place, removing any trailing whitespace.
I recommend using git to track changes, so you can easily revert if something goes wrong.
trim-trailing-whitespace.sh
find . -type f -name "*.md" -exec sed -i -E 's/[[:space:]]+$//' {} +
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow