Find and Replace text in .sql files Find and Replace text in .sql files unix unix

Find and Replace text in .sql files


You can use sed for this. sed stands for S tream Ed itor

sed -i 's/OLDSERVERNAME/NEWSERVERNAME/g' *.sql
  • -i option will do in-file substitution.
  • g implies global substitution. So if there are more than one instances of OLDSERVERNAME in one line they will get replaced with NEWSERVERNAME
  • *.sql will pass all files ending with .sql extension.

Look up sed man page for more details.


On MacOS - I had to add a backup file extension

sed -i '.bak''s/OLDSERVERNAME/NEWSERVERNAME/g' *.sql