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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open file delete lines and close(save) in shell script

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
0
0
CA
Hello All,

I have an sql file that was spawned by another parent job. The drop.sql file contains lines like:
DROP TABLESPACE DATA INCLUDING CONTENTS CASCADE CONSTRAINTS;
DROP TABLESPACE HIST INCLUDING CONTENTS CASCADE CONSTRAINTS;
DROP TABLESPACE INDX INCLUDING CONTENTS CASCADE CONSTRAINTS;
DROP TABLESPACE SYSAUX INCLUDING CONTENTS CASCADE CONSTRAINTS;
DROP TABLESPACE SYSTEM INCLUDING CONTENTS CASCADE CONSTRAINTS;
DROP TABLESPACE RRRR INCLUDING CONTENTS CASCADE CONSTRAINTS;
DROP TABLESPACE LLLL INCLUDING CONTENTS CASCADE CONSTRAINTS;
...
...

I will like to delete these lines and save the shell script back:
DROP TABLESPACE SYSAUX INCLUDING CONTENTS CASCADE CONSTRAINTS;
DROP TABLESPACE SYSTEM INCLUDING CONTENTS CASCADE CONSTRAINTS;

Pleas help on how to do this in shell script.

Note this is a work around for me as I have spent 2 days trying to decipher where the lines are generated within the myriads of jobs (21) that are spawned from the parent job.

your help will be appreciated.

Thanks
 
Something like this maybe?
Code:
mv drop.sql drop.sql.orig
grep -v ' SYSAUX ' drop.sql.orig|grep -v ' SYSTEM ' > drop.sql

 
Hi,
This grep will discard all DROP lines with a 4 chars tablespace name
Code:
grep -v "DROP TABLESPACE.......INCLUDING CONTENTS CASCADE CONSTRAINTS" drop.sql > drop.sql_modified

7 dots stands for 2 spaces and 4 chars tablespace name and a space.
SYSAUX and SYSTEM will be discarded
 
Code:
grep -Ev ' SYS(AUX|TEM) ' drop.sql > drop.$$ && mv drop.$$ drop.sql

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
sed has the -i -switch to modify a file in place.
Code:
sed -i '/SYS\(AUX\|TEM\)/d' foo.sql
would delete all lines containing SYSAUX or SYSTEM. Maybe they occur later too in your file?
Code:
sed -i '5,6/d' foo.sql
will delete the lines 5 to 6 (5,7 would delete line 6 too - it's not a list of matching lines, but a range).

Maybe you can evaluate the linenumbers before with a
Code:
grep -n SYS
to prevent inadvertent deletions.

don't visit my homepage:
 
sed has the -i -switch
AFAIK, only the GNU version of sed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top