SED to remove a line above and lines below.

:confused:Hi All,

I need help on removing lines in a text file.

Sample file :

When there is a match ip for IPAddress in my `cat ip.out`, proceed delete line above until string "Comp" is found.

Thank you very much.

---------- Post updated at 12:56 AM ---------- Previous update was at 12:53 AM ----------

I found very useful SED in this forum but i got no idea how to manipulate it.

sed -rn '/(0\.0000 *){6}/{n;n;x;d};x;1d;p;${x;p}'

:frowning:

To be precise could you pls post the desired output from the above sample file..

Hi,

According to michaelrozar17, I find the post not clear enought. Even so I will make a try:

$ cat infile
Client=0x 0
IPAddress=113.211.45.33
Client=0
ClientV=0
........
Uncomp=0
Comp=0

$ sed '/^IPAddress=113\.211\.45\.33/I , /^Comp=/I { /^IPAddress=/I! d }' infile
Client=0x 0
IPAddress=113.211.45.33

Regards,
Birei

Hi Guy,

Below is the sample output file

TO

I get it resolved by combining all rows and add a newline whenever there is Client string and finally grep -v.

But I still keen to know how to doit.

Thank you in advance.

Try this:

awk '!/113.211.45.33/' RS= ORS="\n\n" file