Need to change a set of lines between two given Pattrens


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to change a set of lines between two given Pattrens
# 1  
Old 03-21-2007
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...
# 2  
Old 03-22-2007
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
# 3  
Old 03-22-2007
Code:
sed -n '/EVALUATE WS-TEMP-ATTR(15:1)/,/END-EVALUATE/p' filename  | sed 's/.*/TCSCMT* &/'

# 4  
Old 03-22-2007
Quote:
Originally Posted by Raghuram.P
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
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??
# 5  
Old 03-22-2007
Quote:
Originally Posted by matrixmadhan
Code:
sed -n '/EVALUATE WS-TEMP-ATTR(15:1)/,/END-EVALUATE/p' filename  | sed 's/.*/TCSCMT* &/'

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??
# 6  
Old 03-22-2007
Quote:
Originally Posted by pbsrinivas
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??
Code:
sed -n '/EVALUATE WS-TEMP-ATTR(15:1)/,/END-EVALUATE/p' filename  | sed '/^TCSCMT/!s/^/TCSCMT* /'

# 7  
Old 03-22-2007
Quote:
Originally Posted by matrixmadhan
Code:
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??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to change a set of characters between delimiters?

Hi all, I am trying to write a script for renaming some files and I can't understand how to replace a set of characters between delimiters with sed. The current filename is: <ID1>_<ID2>_<DATE>_<ID3>.PDF And I need to get the following: <ID1>_<ID2>_<DATE>_X01<ID2>.PDF I have tried the... (5 Replies)
Discussion started by: bartleby
5 Replies

2. Red Hat

PROC_MEM_RES how to set/unset/change

Hi all, Does anyone know how to change PROC_MEM_RES? We have a DB server with quite a few oracle instances (RAC) and we are getting critical alerts for PROC_MEM_RES. Anyone know how to increase the current setting or what we should do about it? Thanks in advance. john (2 Replies)
Discussion started by: jonnyd
2 Replies

3. Shell Programming and Scripting

Replacing certain lines with another set of lines

i have a huge script that i need to replace a bunch of lines in. in that script, i have a chunk similar to: JABABA=$(if ; then echo afafafa afafafafaf afafafafe fdfdfdfadfadl fafafafkkkk fi) I would like to replace the above chunk with: (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

5. Solaris

help me to change the character set

dears i am using solaris 10 i am facing a problem when i make setup for solaris i choose the country egypt and i select the language north america but i forget to do that the i found the date Jun written in arabic i want to change character set to written in english -rw-r--r-- 1 root ... (4 Replies)
Discussion started by: hosney00ux
4 Replies

6. UNIX for Dummies Questions & Answers

Change permission for a set of files

Hi there, I want to change from this permission -r-xr-xr-x to -r-xr-xr-- for a set of files under unix. Can someone help me to go-about doing this in one shot. Cheers, RN (2 Replies)
Discussion started by: karthickrn
2 Replies

7. UNIX for Dummies Questions & Answers

Why does set also change setenv variables?

I thought that set and setenv was easy enough to understand until I started experimenting. I noticed the same problem in a previous thread, so I will use it as an example. set command gave the following output: argv () cwd /homes/e/ee325328/assignment.2 home /homes/e/ee325328 path ( a... (2 Replies)
Discussion started by: benwj
2 Replies

8. Shell Programming and Scripting

Search between pattrens with one string in one or other line........

Hi have a lots of files with this type of code Example--1 PROCEDURE DIVISION USING AAA BBB CCC. Example--2 PROCEDURE DIVISION Some Commented Lines.... USING AAA BBB CCC. Example--3 (12 Replies)
Discussion started by: pbsrinivas
12 Replies

9. Shell Programming and Scripting

Search and insert between Pattrens...

Hi Every One... I wanted to inserted a line in between matched pattrens.. Ex... InPut File.. WRITEQ TS ************************** aaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccc SOME PATTREN's RESP ( WS-RESP ) ... (7 Replies)
Discussion started by: pbsrinivas
7 Replies

10. Shell Programming and Scripting

Search between pattrens.

i wanted to search between pattrens so i used awk /"EXEC CICS DELETEQ TS"/,/END-IF/ but the some change is AAAAAAAA EXEC CICS DELETEQ TS IF ..... END-IF.... XXXXXx XXX IF (3 Replies)
Discussion started by: pbsrinivas
3 Replies
Login or Register to Ask a Question