I have a sql file exported from mysql,and want to chang the charecter
set to utf-8.
sqltempfile=File.new(sqltemp,'w+') ### How to get rid of it?
File.open(sqlfile,'r+') do |file|
lines=file.gets(nil)
lines.gsub!(/TYPE=MyISAM/){|match| match='DEFAULT CHARACTER SET
utf8'}
sqltempfile.puts lines ### How to get rid of it?
end
sqltempfile.close ### How to get rid of it?
And the question is,how to replace the string directly without
sqltempfile?
Anyone help me?
ruby -i -p -e 'gsub! /TYPE=MyISAM/, "DEFAULT CHARACTER SET utf8"' your_file
If you want backups, you can use "-i.bak" instead of "-i".
robert
···
On 16.10.2006 12:49, camenix wrote:
I have a sql file exported from mysql,and want to chang the charecter
set to utf-8.
sqltempfile=File.new(sqltemp,'w+') ### How to get rid of it?
File.open(sqlfile,'r+') do |file|
lines=file.gets(nil)
lines.gsub!(/TYPE=MyISAM/){|match| match='DEFAULT CHARACTER SET
utf8'}
sqltempfile.puts lines ### How to get rid of it?
end
sqltempfile.close ### How to get rid of it?
And the question is,how to replace the string directly without
sqltempfile?
Anyone help me?
s = nil
open(myfile, 'r') {|f| s = f.read}
open(myfile, 'w') {|f| f.puts s.gsub("TYPE=MyISAM", "DEFAULT CHARACTER
SET utf8")}
m.
···
camenix <vipeak@gmail.com> wrote:
> On 16.10.2006 12:49, camenix wrote:
> > I have a sql file exported from mysql,and want to chang the charecter
> > set to utf-8.
> >
> > sqltempfile=File.new(sqltemp,'w+') ### How to get rid of it?
> > File.open(sqlfile,'r+') do |file|
> > lines=file.gets(nil)
> > lines.gsub!(/TYPE=MyISAM/){|match| match='DEFAULT CHARACTER SET
> > utf8'}
> > sqltempfile.puts lines ### How to get rid of it?
> > end
> > sqltempfile.close ### How to get rid of it?
> >
> > And the question is,how to replace the string directly without
> > sqltempfile?
> > Anyone help me?
> >
>
> ruby -i -p -e 'gsub! /TYPE=MyISAM/, "DEFAULT CHARACTER SET utf8"' your_file
perlish script.Ugly,but worked.