Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hilam/90771870df8cb4d8d1e28eb17909a447 to your computer and use it in GitHub Desktop.
Save hilam/90771870df8cb4d8d1e28eb17909a447 to your computer and use it in GitHub Desktop.
How to replace a string in a file? — First published in fullweb.io issue #84

How to replace a string in a file?

The simplest way to proceed is to use sed. It‘s available both on Mac and Linux. Here is the gist of it:

sed -i 's/old/new/g' file.txt

Here we’re replacing old with new. The -i option will replace the string inplace. The /g flag will replace every occurrences in the file.

Good reference: https://likegeeks.com/sed-linux/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment