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

  Work with me!


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 )

Thank you for reading! And see you soon on Strangebuzz! 😉

COil