Re: enhanced search and replace

From: Arthur Corliss <acorliss@nevaeh-linux.org>
Date: Wed Feb 23 2005 - 20:43:58 AKST

On Wed, 23 Feb 2005, Clay Scott wrote:

> i've got a mysql dump file from an app i'm helping on, but the author added three new fields to one of the tables in the latest release. now the dump file i generated won't import because mysql complains that the number of fields doesn't match that of the dump file (32 fields in the table, the dump file has 29). so i'm trying to come up with a quick command to parse the .sql file, search for the lines that start with INSERT INTO <table> VALUES blah and replace the ); on the end of the line with ,'','',''); so it thinks the three new fields are represented, but blank.
>
> i'd do it by hand if there weren't about 5000 entries to be modified. i was going to just split the lines for this table out since four tables are represented in the dump file, but this is something i'd like to know.... that and i'm slightly regex-retarded.

Make a backup of the file and try something like:

  sed -i 's/^\(INSERT INTO foo .*\));/\1,"","","");/' mysql.dump

Now this is assuming you don't have any string/text fields with newlines as
part of any values.

        --Arthur Corliss
          Bolverk's Lair -- http://arthur.corlissfamily.org/
          Digital Mages -- http://www.digitalmages.com/
          "Live Free or Die, the Only Way to Live" -- NH State Motto
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed Feb 23 20:43:55 2005

This archive was generated by hypermail 2.1.8 : Wed Feb 23 2005 - 20:43:55 AKST