deleting lines

I am trying deleting lines from a text file using sed..

sed '/OBJECT="ABC/{N;N;N;d; }'

will do if i have to delete lines starting with Object and next 3 lines
but I was looking for a way to delet lines starting with OBJECT and all the lines till it reaches a blank lines ..or it reaches a line with OBJECT in it ...

i tried all kind of things .. didn't work .

Will appreciate help

thanks in advance ..
:frowning:

You have to use a loop...

#! /usr/bin/ksh
target=OBJECT
sed -n -e "
s/${target}//
t loop
p
b
:loop
s/.*//
n
s/${target}//
t
b loop"
exit 0

Not that I can decipher how that works :stuck_out_tongue: but I invoked it (assuming your script is called theScript and the OP's text file is called theFile) by typing theScript < theFile and it deletes any line with the word OBJECT on it as well as the line immediately following any line with the word OBJECT on it, but nothing else..

this script deletes line with pattern and again search for pattern and deletes it ..
May be i haven't explained properly...
Once i delete the line with pattern i need to delete all the lines after the pattern till the time it sees a blank line.
I am working on database file ..
which is in this format ..
OBJECT="NAME" ACTION="REDEFINE" "NAME_A"="KAJNABI-XYZ"
DESCRIPTION="FGH"
.
.
.
.
AUTO_RESET="0"
.
.
.
*****BLANK LINE
OBJECT="NAME" ACTION="REDEFINE" "NAME_A"="AJNABI-GFT"
DESCRIPTION="GFR"
.
.
.
.
AUTO_RESET="0"
.
.
.

OBJECT="NAME" ACTION="REDEFINE" "NAME_A"="KAJNABI-XYZ"
DESCRIPTION="FGH"
.
.
.
.
AUTO_RESET="0"
.
.
.

WHAT i need to do is delete line with pattern say KAJNABI and delete all the lines after it till it sees the blank line .. and again search for the pattern and does the same again ...
I understand that i will have to use the loop but how exactly I am going to do this .. makes me confused ....

thanks

I understand the script in general now..

From what I see, the part where n deletes the next line should delete all lines until the next $target is found, but it doesn't; however, the second instance of s/${target}// should actually be searching for a blank line instead of $target..

I tested my script again and it continues to work for me. It starts deleting when it sees a line containing "OBJECT". It keeps on deleting until it sees a second line containing "OBJECT". Then it starts over again.

code:--------------------------------------------------------------------------------#! /usr/bin/ksh
target=OBJECT
sed -n -e "
s/${target}//
t loop
p
b
:loop
s/.*//
n
s/^$// # till the blank line
t
b loop"
exit 0

did the job ...
Thanks perderabo ...
but for some reason i was running script the way it was .. was just deleting one line containing the pattern...Just curious why it ws doing that .. i was trying running this script on database file .. its in the format the way i mentioned in my post...and say my pattern is KAJNABI ...

This is the best forum i have seen ....

Thanks guys

Odd that it does something different for all of us! :slight_smile:

ajnabi's code works for me too.. at first I thought you wanted to delete the first line with the word OBJECT on it, then every line after it up to and including the next line with the word OBJECT on it, which is really easy to do but unfortunately isn't what you needed:

sed -e '/OBJECT/,//d' yourFile

right oombera,
This commands does the same what perderabo wrote and it is running fine ... it looked like to me it was deleting first line but when I saw it closely .. it was delelting from pattern to the next pattern and hence leaving the lines after it finds the pattern second time ...
so result lookes like it's delelting first line but actually it was deleting half the record..

cheers