Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK help required

Status
Not open for further replies.

newbee1310

Technical User
Jul 22, 2013
1
GB
Hi,
I am having a file(new.sql) containing create table statements(mysqldb), i am trying to modify engine type and other few strings in the last line of each table creation.

I tried the below sed which modified engine type but i need help in removing the default charset and add the connection string.

sed -i 's/ENGINE=InnoDB /ENGINE=FEDERATED /g' new.dmp

Original table
CREATE TABLE `test` (
`column1` varchar(200) NOT NULL,
`column2` varchar(200) NOT NULL,
`BLOB_DATA` blob,
PRIMARY KEY (`column1`,`column2`),
KEY `dummy` (`column1`,`column2`),
CONSTRAINT `test` FOREIGN KEY (`column1`,`column2`) REFERENCES `test2` (`column1`,`column2`)
) ENGINE=InnoDB AUTO_INCREMENT=1948988 DEFAULT CHARSET=utf8;;

Modified table
CREATE TABLE `test` (
`column1` varchar(200) NOT NULL,
`column2` varchar(200) NOT NULL,
`BLOB_DATA` blob,
PRIMARY KEY (`column1`,`column2`),
KEY `dummy` (`column1`,`column2`),
CONSTRAINT `test` FOREIGN KEY (`column1`,`column2`) REFERENCES `test2` (`column1`,`column2`)
) ENGINE=federated AUTO_INCREMENT=1948988 connection='fed_test';

Thanks
Newbee
 
What about this ?
Code:
sed '/ENGINE=InnoDB/{s!InnoDB!federated connection='"'fed_test'"'!;s! DEFAULT CHARSET=utf8!!;}' inputfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top