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

Deleting a line based on next line 1

Status
Not open for further replies.

vrrajeeb

Technical User
Feb 16, 2003
13
US
Hi,

I have a file which contains the following :

conn scale/****@bill;
conn audit/****@accounts;
conn ledger/****@receive;
drop synonym tested;
drop synonym checked;
conn rule/****@stats;
drop synonym booked;
drop synonym billed;
drop synonym removed;

.....................

1) I want the connect statements, with no drop statements under them, to be removed ...

2) And each conn statement should have a blank statement before and after it ...

The required output is as follows :

conn ledger/****@receive;

drop synonym tested;
drop synonym checked;

conn rule/****@stats;

drop synonym book;
drop synonym billed;
drop synonym removed;

...................

Can anyone help me please ?

Thanx

-Maria
 
Try this...

awk '/^conn /{c=$0}/^drop /{if(c){print "\n" c "\n";c=""}print $0}' file1 > file2
 
That worked like a charm ! Thanx a great bunch !!!

-Maria
 
Hey,

How do I select create, grant statements along with drop ?

From this :

conn scale/****@bill;
conn audit/****@accounts;
conn ledger/****@receive;
drop synonym tested;
drop synonym checked;
create synonym test for scale.book;
grant select on test to public;
conn rule/****@stats;
drop synonym booked;
drop synonym billed;
drop synonym removed;

.....................

To this:

conn ledger/****@receive;

drop synonym tested;
drop synonym checked;
create synonym test for scale.book;
grant select on test to public;

conn rule/****@stats;

drop synonym book;
drop synonym billed;
drop synonym removed;

...................

Rgds

-Maria
 
Ok, I got it :

awk '/^conn /{c=$0}/^(create|grant|drop) /{if(c){print "\n" c ;c=""}print $0}' file1 > file2

Thanx

-Maria
 
Try this instead...

awk '/^conn /{c=$0}!/^conn /{if(c){print "\n" c "\n";c=""}print $0}' file1 > file2
 
or..... (just to be really lazy)

egrep 'create|grant|drop' file1 > file2

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Ygor's second solution also works Great !

Mike's solution doesn't work ...

Thanx a lot for all your help

-Maria
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top