Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    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.

  3. #3
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    If you want to replace \' with nothing this should work:

    Code:
    sed 's/\\'"'"'//g' file > newfile
    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
    Regards

  4. #4
    Just 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...