to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference
[

 
http://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569

](http://www.unix.com/shell-programming-scripting/171076-shell-scripting.html\#post302573569)

consider there is create table commands in a file for eg:

CREATE TABLE `Blahblahblah` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`action` enum('Change','Delete','Add','Locked','Unlocked') COLLATE utf8_unicode_ci DEFAULT 'Change',
`date` datetime DEFAULT NULL,

`reserved1` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`reserved2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`zoneId` int(11) DEFAULT NULL,
) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

like the above block there are many blocks in the file, i mean many create table queries in the file.
i have two doubts which i need help in
1) what i need to do is separate out one create table block based on idetifier such as "create table" which is the start and "ENGINE=" as end and seperate it out and write to a file for processing (which i will be doing in a while loop so that every time a new create table overwrite in that particular file for processing).
2) if i have a string "CREATE TABLE `Blahblahblah`" in a variable how to extract `blahblahblah` and store it in a variable..?

help on these is deeply appreciated
thanks :confused:

Whatever you have mentioned can be done, but what is your ultimate goal?...

table_name=$( awk -F\` '/CREATE TABLE/{print $2}' input_file )

--ahamed

1 Like

my goal is to write a shell script which takes two mysql dump files(one is latest dump which has new changes to be made and other one is older mysql dump) the script compares both the files and and give the delta (that is changed to to be made ) as output. the changes in the sense.. new mysql dump file has two more columns added in the table blahblahblah so the scipt finds out which are the columns missing and from which table and writes alter table query to that particular table. i am stuck in the part where i need to extract table wise from the file and also in comparison between files. right now i have wrote shell script which just prints out lines missing from one file compared to other.. its copy is shown in
[

 
http://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569

](http://www.unix.com/shell-programming-scripting/171076-shell-scripting.html\#post302573569)
thanks for replying in short time

---------- Post updated at 03:45 PM ---------- Previous update was at 03:41 PM ----------

this is required for my project since currently we use mysql testbench to get this delta changes of database compared to new changes. and use this delta changes file to alter the old database so that it reflects all the new changes. but i want to avoid using testbench for this function and write a shell script which performs its functions.

---------- Post updated at 05:47 PM ---------- Previous update was at 03:45 PM ----------

the above query works good thanks.. :slight_smile:
consider the below code

`id` int(11) NOT NULL AUTO_INCREMENT,
`action` enum('Change','Delete','Add','Locked','Unlocked') COLLATE utf8_unicode_ci DEFAULT 'Change',
`date` datetime DEFAULT NULL,

`reserved1` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`reserved2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`zoneId` int(11) DEFAULT NULL,

these are the column names in the earlier mentioned table. how to extract these column names dynamically cause i want to use it in a function so if i send either
`reserved2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL
or
`zoneId` int(11) DEFAULT NULL
(the above two line will be stored in the variable.. i am using while loop to read from file so technically in first run one column will be held in $line )
it should extract reserved2 or zoneid respectively.. how to do it..?