Find and Replace text in Linux/OSX

This information is covered in several other blogs, tutorials and etc… but as my google skills tend to send me someplace different¬†every time¬†I search (yes I know bookmarks) I might as well leave it here for my future reference

Find text

grep "what to find" "fileToFind"

Replace text in a file (OSX, notice the empty quotes at the beginning)

sed -i "" 's/text_to_replace/what_to_replace_with/g' file_where_replacement_occurs

And in Linux the syntax is similar

sed -i 's/text_to_replace/what_to_replace_with/g' file_where_replacement_occurs

Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *