Post

How to replace text in lots of file via sed and find

How to use find and sed together to perform bulk text replacement across multiple Markdown files.

I have recently decided to change the way how my code blocks look like at this blog. This was rather straightforward change. I needed to exchange “bash" to "”.

Here is an easy way how this can be achieved via find and sed. The find command locates all Markdown files, and sed -i performs an in-place replacement. On macOS, sed -i '' requires the empty string argument for the backup extension.

1
2
find content/english -type f -name '*.md' -exec sed -i '' -e 's|\`\`\`bash|\`\`\`|g' {} +
'
This post is licensed under CC BY 4.0 by the author.