Results 1 to 4 of 4
Hey I was converting excel files for use in a mysql database.
I converted the xls to mdb then found a tool that converts mdb to mysql.
Long story short ...
- 02-19-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 2
Grep a odd string
Hey I was converting excel files for use in a mysql database.
I converted the xls to mdb then found a tool that converts mdb to mysql.
Long story short the mysql seems to have a problem with the insert statements, when I edit the file with geany the syntax goes weird with \' in the varchars. I think the \ is added to every word it ' in it, ie doesn't goes to doesn\'t. The syntax is also bad when I get rid of the \ ie doesn't.
So is it possible to maybe grep the .sql for every \' and replace it with nothing.
I tried simply grep \' myfile.sql and it returns every line.
Can anyone help???
Thanks.
- 02-19-2008 #2
Don't you want to preserve the apostrophe?
e.g. "Doesn't" is different than "Doesnt". (The latter is neither a contraction nor a word at all.)
Personally I'd look closely at other options/features available in the conversion tool. Someone must have thought of a case where apostrophes need to be kept.
- 02-19-2008 #3Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
If you want to replace \' with nothing this should work:
However, as anomie mentioned "Doesn't" is different than "Doesnt" so if you only want to delete the backslash you can do something like:Code:sed 's/\\'"'"'//g' file > newfile
RegardsCode:sed 's/\\//g' file > newfile
- 02-19-2008 #4Just Joined!
- Join Date
- Feb 2008
- Posts
- 2
Yeah I'm thinking the conversion tool adds the \ behind all apostrophes, to preserve the data. My text editor was detecting this as a problem.
However this wasn't the problem at all.
It turns out when people we're entering text into the system the would sometimes accidently press \ so the mysql tables had \' which made the sql inserting tool go crazy. So I took out the few rare instances it happened and the data inserted perfectly.
Thanks very anomie and Franklin for your help


Reply With Quote