Joerg Bruehe wrote:
> Duncan Hill wrote:
>> On Thursday 19 April 2007 15:53:54 molemenacer wrote:
>>> I am trying to change all the names of the database from mthosp to
>>> name, is this possible?
>> Assuming you mean tables, not database (as mysqldump doesn't store the
>> database name in the dump file [or at least never has for me]):
>> sed -e 's/mthosp/another_name/' < source.sql > dest.sql
> 1) This is risky, because it will also change (for example)
> "govmthospital" to "govanother_nameital" which may be a bit more than
> is intended.
> Sure, you can add conditions that prevent some such issues, but it
> will get complicated.
> The regular expressions the "sed" can handle are somewhat limited,
> when you compare them to what Perl can do.
> (Sorry, I won't give a Perl command - this is still too risky.)
>> mysql> rename table mthosp_1 to another_name_1, mthosp_2 to
>> (Check the manual for syntax)
> 2) If you want multiple changes in a line, add the "g" modifier at the
> command end:
> sed -e 's/mthosp/another_name/g' < source.sql > dest.sql
> 3) Most likely, you should first run a grep on the file, to check where
> the string occurs and which effects your commands have.
> 4) *If* you decide to use sed, then a cheap way to see just the changes
> is this:
> sed -n -e 's/mthosp/another_name/gp' < source.sql > verify.sql
> This will output *only* the changed lines, not the unchanged ones.
> However, it will not show the context - if you want to get that as
> well, then you will need a more complicated sed command or (easier,
> IMHO) a pipe of grep (providing the context, see the -A and -B
> options) and sed (above).
That reminds me of the story of the mailing list maintainer who decided
to replace 'and' with '&'.
He ended up sending mail to S&y S&erson.
Gerald L. Clark
Supplier Systems Corporation