I dont know shell scripting, It will be great help if someone help me in writing the script for below requirnment

Requirnment:
I have a file in which sql quires are written.I have to replace content of that file.

sql file looks some what like below

#partial content of the a.sql file

insert into Table_1 values
 ( 'object1', 'attribute1', 'OPTIONAL', 'attr' );

insert into Table_2  values
 ( 'object1', 'attribute1', 'OBJECTID', '10', ' ', 'OPTIONAL', ' ', ' ', 'OPTIONAL', 'NOSAVECHECK', 30 );

insert into Table_1 values
 ( 'object1', 'attribute2', 'OPTIONAL', 'cr_otendpo' );

insert into Table_2  values
 ( 'object1', 'attribute2', 'OBJECTID', '10', ' ', 'OPTIONAL', [B]' '[/B], ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute3', 'OBJECTID', '10', ' ', 'OPTIONAL',[B] ' '[/B], ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute4', 'OBJECTID', '10', ' ', 'OPTIONAL',[B] ' '[/B], ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute5', 'OBJECTID', '10', ' ', 'OPTIONAL',[B] ' '[/B], ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute6', 'OBJECTID', '10', ' ', 'OPTIONAL', [B]' '[/B], ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute7', 'OBJECTID', '10', ' ', 'OPTIONAL', [B]' '[/B], ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_1 values
 ( 'object1', 'attribute8', 'OPTIONAL', 'attr' );

In above a.sql file i have to replace 7th column ' ' (marked in green color above a.sql file code) in Table_2 to 'ReplacedSucessfully'.

output should look like below

insert into Table_1 values
 ( 'object1', 'attribute1', 'OPTIONAL', 'cr_otendpo' );

insert into Table_2  values
 ( 'object1', 'attribute1', 'OBJECTID', '10', ' ', 'OPTIONAL', 'ReplacedSucessfully', ' ', 'OPTIONAL', 'NOSAVECHECK', 30 );

insert into Table_1 values
 ( 'object1', 'attribute2', 'OPTIONAL', 'cr_otendpo' );

insert into Table_2  values
 ( 'object1', 'attribute2', 'OBJECTID', '10', ' ', 'OPTIONAL', 'ReplacedSucessfully', ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute3', 'OBJECTID', '10', ' ', 'OPTIONAL', 'ReplacedSucessfully', ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute4', 'OBJECTID', '10', ' ', 'OPTIONAL', 'ReplacedSucessfully', ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute5', 'OBJECTID', '10', ' ', 'OPTIONAL', 'ReplacedSucessfully', ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute6', 'OBJECTID', '10', ' ', 'OPTIONAL', 'ReplacedSucessfully', ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_2  values
 ( 'object1', 'attribute7', 'OBJECTID', '10', ' ', 'OPTIONAL', 'ReplacedSucessfully', ' ', 'OPTIONAL', 'NOSAVECHECK', 31 );

insert into Table_1 values
 ( 'object1', 'attribute8', 'OPTIONAL', 'cr_otendpo' );

Recommended Answers

All 2 Replies

sed "p;s/^\(\([ (]*'[^',]*', \)\{6\}\)' '/\1'X'/g" filename assumes number of spaces etc is fixed, if not put a few +s and *s appropriately.

remove the p command from sed, it's for showing your before and after effect not needed in production code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.