replace - multiline regex match string replacement on large file -


i have large mysqldump (4+ gigs), , have archive type table suffers bug net result need reset auto_increment counter zero. did manage replacement, ugly, involving splitting file smaller chunks, grepping find table, looking see number wanted change , using sed on original file replace match on auto increment. said, horrible, worked.

so - have tried decipher multiline sed , didn't far. want seek table name i'm interested in, , point find next auto_increment= , , match number in it, , make zero. here's table: (assume there scads of data before point, , after it)

drop table if exists `archive_exported_problems`; /*!40101 set @saved_cs_client     = @@character_set_client */; /*!40101 set character_set_client = utf8 */; create table `archive_exported_problems` (   `id` int(11) not null auto_increment,   `export_id` int(11) default null,   `problem_id` int(11) default null,   primary key (`id`) ) engine=archive auto_increment=478 default charset=latin1; 

what want do, (automatically) scan file until matches

(?:create table `archive_exported_problems).*?auto_increment=(\d+) 

(regex seems work) , replace capture group 0

i assume possible - appreciated!

if perl option easier using dotall flag in perl this:

perl -00 -pe   's/(?s)(create table `archive_exported_problems`.*?auto_increment)=\d+/$1=0/' file.sql  drop table if exists `archive_exported_problems`; /*!40101 set @saved_cs_client     = @@character_set_client */; /*!40101 set character_set_client = utf8 */; create table `archive_exported_problems` (       `id` int(11) not null auto_increment,       `export_id` int(11) default null,       `problem_id` int(11) default null,       primary key (`id`) ) engine=archive auto_increment=0 default charset=latin1; 

options used are:

-00    # slurps whole file (?s)   # enable dotall flag regex 

Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -