sed to find replace mutliline text

Hi,

My input file

form 1
fill 2
fill 3
form 4
fill 5
form 6
fill 7
form 8
 

Now i need to substiute according to the fill.
form followed by single fill need to be replced with category 1
form with above and below fill need to be repalced with category 2

Desired output:

category1  1
category2  4
category2  6
category1  8

I tried like

awk '{print $1}' input_file | sed -e 's/form\\nfill/category1/g' -e 's/fill\\nform\\nfil/category2/g' 

But it doesnot worked. anybody have answer..

Thanks in advance,
Vasanth

Try this.

awk '/form/{if($2<2 || $2>7){print "category 1",$2} else {print"category 2",$2}}' file

Dear protocomm,

your code worked well and thanks a lot.

Thanks
vasanth

---------- Post updated at 09:40 AM ---------- Previous update was at 09:14 AM ----------

Dear Protocomm,

Your code worked, but for more than 8 lines the desired output fails.

Desired output:

Check for form
check above and below  fill word
if above and below fill found, then it is category2.
If only one filll either above or belo, then category1.

sorry - misread the req

nawk '$1=="form" {print "category" ++c, $2}' myFile

Dear Vgersh,

Thanks for your reply.

In the above script category is in increasing order. But in desired output catergory is total 2 only. it have to be printed according to the condition stated:

use form as reference and check below and above fill word, if only one fill found then it should go to category1 and if two fill found then it will be category2.

Thanks in advance,
Vasanth

---------- Post updated at 10:56 PM ---------- Previous update was at 10:26 PM ----------

Hi,

Anybody can help for the above issue..

Thanks in advance
Vasanth

---------- Post updated 10-30-09 at 12:52 AM ---------- Previous update was 10-29-09 at 10:56 PM ----------

Dear friends,

i tried using sed script

{
N
s/form\nfill/category1\n/
}

But it not serving my requirement.

Anybody have answer?

Thanks in advance,
Vasanth

---------- Post updated at 06:08 AM ---------- Previous update was at 12:52 AM ----------

Hi

Anybody have answer for the above problem.

Thanks in advance,
Vasanth

Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.