Need to change a set of lines between two given Pattrens

Hi All

I have a Small Requiement

I wanted to replace all the Follwing lines as follows

Input:: file1

       EVALUATE WS-TEMP-ATTR\(15:1\)
          WHEN 'D'
               MOVE DFHDARK         TO WS-ATTR-COLOR
           WHEN OTHER
               MOVE DFHDFT         TO WS-ATTR-COLOR
       END-EVALUATE.

Output::file2

TCSCMT* EVALUATE WS-TEMP-ATTR(5:1)
TCSCMT* WHEN 'D'
TCSCMT* MOVE DFHDARK TO WS-ATTR-COLOR
TCSCMT* WHEN OTHER
TCSCMT* MOVE DFHDFT TO WS-ATTR-COLOR
TCSCMT* END-EVALUATE.

I have Tried Some thing of this sort with sed

sedscript File

/ EVALUATE WS-TEMP-ATTR(5:1)/c\
TCSCMT* EVALUATE WS-TEMP-ATTR(5:1)
/ WHEN 'D'/c\
TCSCMT* WHEN 'D'
/ MOVE DFHDFT TO WS-ATTR-COLOR/c\
TCSCMT* MOVE DFHDFT TO WS-ATTR-COLOR
/ WHEN 'OTHER'/c\
TCSCMT* WHEN 'OTHER'
/ MOVE DFHDFT TO WS-ATTR-COLOR/c\
TCSCMT* MOVE DFHDFT TO WS-ATTR-COLOR
/ END-EVALUATE./c\
TCSCMT* END-EVALUATE.

sed -f sedscript file1 > file2

I have got what i wanted but.......

If i have more than one END-EVALUATE in the file1 the it is replacing everything

But i want it to happen only between these two line
1 EVALUATE WS-TEMP-ATTR(5:1)
2 END-EVALUATE

So thats it doesn't Effecft others

This is basically to comment the Paticular set of lines in the code...

HI,
If you can use AWK then try this awk code
BEGIN{
COMMENT="TCSCMT* ";
}
{
if($0 ~ /^EVALUATE/)
{
printf("%s%s\n",COMMENT,$0);
getline;
while(1)
{
printf("%s%s\n",COMMENT,$0);
if($0 ~ /^END-EVALUATE/)
{
break;
}
getline;
}
}
else
{
printf("%s\n",$0);
}
}
END{
}
Thanks
Raghuram

sed -n '/EVALUATE WS-TEMP-ATTR(15:1)/,/END-EVALUATE/p' filename  | sed 's/.*/TCSCMT* &/'

Hi Raghu...

This working and it almost Solved my Requirement but...

IF i have some thing like

TCSCMT* MOVE OTHER TO COLOR
then is putting
TCSCMT*TCSCMT* MOVE OTHER TO COLOR

That is its PreFixing the TCSCMT* but i want the Whole line to get Replaced(basically the first 7 Chars are SPACES or ??????* for me )
So i want the 1st 7 Chars to be REPLACED by TCSCMT*

Can we replace instead of Prefixing??

Hi Madhan

This is woking but... some problem of that of Raghu's Post....

It Prefixing the TCSCMT* 7 CHars to what ever is there on that line

Can we Replace the 1st 7 Chars instead??

sed -n '/EVALUATE WS-TEMP-ATTR(15:1)/,/END-EVALUATE/p' filename  | sed '/^TCSCMT/!s/^/TCSCMT* /'

Sorry Madhan if u was not clear in what i wanted but...

The 1st 7 Chars can be any thing .... I want them to be replaced with TCSCMT*
sed -n '/EVALUATE WS-TEMP-ATTR(15:1)/,/END-EVALUATE/p' filename is getting me the Lines between EVALUATE WS-TEMP-ATTR(15:1) and END-EVALUATE

and then of all those line irrespective of what the 1st 7 Charecters or i want them to be TCSCMT*

sed '/^TCSCMT/!s/^/TCSCMT* /' i hope this Checks it its not starting with TCSCMT and then Prefixes TCSCMT* but irrespective of what the 1st 7 Charecters or i want them to be TCSCMT* Can we do that??

Try...

sed -e '/EVALUATE WS-TEMP-ATTR/,/END-EVALUATE/ s/^......./TCSCMT\*/' file1 > file2

Wow that was Great......

Thansk a Lot!!!

instead of 7 ' . ' s

sed -e '/EVALUATE WS-TEMP-ATTR/,/END-EVALUATE/ s/^\(.\{7\}\)/TCSCMT\*/' filename