Skip to content

Instantly share code, notes, and snippets.

@erikw
Last active January 18, 2022 19:48
Show Gist options
  • Save erikw/ea93364607376659bdcfb9e835e94539 to your computer and use it in GitHub Desktop.
Save erikw/ea93364607376659bdcfb9e835e94539 to your computer and use it in GitHub Desktop.
sed inline -s compatible with both Linux and BSD/macOS
# To be compatiable with both GNU sed and the old BSD sed that macOS uses, need to set and inplace backup extension and then remove the file.
# $(sed -i -e '...' file) works with GNU sed and modern BSD. However on macOS a backup file "file-e" will be created
# Reference: https://unix.stackexchange.com/a/131940/19909
sed -i.bak -e 'expr...' file && rm file.bak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment