Replacing text in a file with SED on macOS
Published on 2021-07-14 • Modified on 2021-07-14
In this snippet, we see how to replace text in a file with SED on macOS. Sometimes Unix commands do not behave exactly as they would when using Unix. This SED command is a good example where the file you try to modify is being emptied. To prevent that, you can use the following commands:
sed 's/APP_ENV=dev/APP_ENV=prod/g' .env > .env.new && mv .env.new .env
sed -i '' 's/APP_ENV=dev/APP_ENV=prod/g' .env
More on Stackoverflow Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉