Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-11-2007
Registered User
 

Join Date: Jul 2006
Posts: 141
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 )
END-EXEC

Out Put...

WRITEQ
TS
**************************
aaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccc
SOME PATTREN's
dddddddddddddddddddddddd
TSQCHG MAIN
RESP ( WS-RESP )
END-EXEC



I have Tried Some thing of this sort...

/[ ]*WRITEQ/,/[ ]*END-EXEC{ /[ ]*RESP/a\
TSQCHG MAIN/;}

Search for lines between WRITEQ and END-EXEC and on matched ones after RESP insert TSQCHG MAIN
but this doesnot work.... Gives some error while running...

sed: 0602-403 /[ ]*WRITEQ/,/[ ]*END-EXEC{ /[ ]*RESP/a\
TSQCHG MAIN/;} is not a recognized function.
Sponsored Links
  #2 (permalink)  
Old 06-11-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,574

Code:
awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print; print "TSQCHG MAIN";next}}; 1' filename


Code:
sed "/WRITEQ/,/END-EXEC/{/RESP/s/$/\\
TSQCHG MAIN/;}" filename


Last edited by anbu23; 06-11-2007 at 03:11 AM..
  #3 (permalink)  
Old 06-11-2007
Registered User
 

Join Date: Jul 2006
Posts: 141
Quote:
Originally Posted by anbu23
Code:
awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print; print "TSQCHG MAIN";next}}; 1' filename


Code:
sed "/WRITEQ/,/END-EXEC/{/RESP/s/$/\\
TSQCHG MAIN/;}" filename



that was a beauty....

One small addition...

if RESP is not found can we do it before END-EXEC...(only if RESP not Found)

Example....
WRITEQ
TS
**************************
aaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccc
SOME PATTREN's
END-EXEC

Out Put...

WRITEQ
TS
**************************
aaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccc
SOME PATTREN's
dddddddddddddddddddddddd
TSQCHG MAIN
END-EXEC
  #4 (permalink)  
Old 06-11-2007
Registered User
 

Join Date: Jul 2006
Posts: 141
awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print; print "TSQCHG MAIN";next}}; 1' filename

i have changed this to

awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) { print "TSQCHG MAIN";print;next}}; 1' filename

to print TSQCHG MAIN before RESP...
but if the RESP is not found i wanted that to be before "END-EXEC"....
  #5 (permalink)  
Old 06-11-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,574
Quote:
Originally Posted by pbsrinivas
that was a beauty....

One small addition...

if RESP is not found can we do it before END-EXEC...(only if RESP not Found)

Example....
WRITEQ
TS
**************************
aaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccc
SOME PATTREN's
END-EXEC

Out Put...

WRITEQ
TS
**************************
aaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccc
SOME PATTREN's
dddddddddddddddddddddddd
TSQCHG MAIN
END-EXEC

Code:
awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print; print "TSQCHG MAIN";next; flag=1}
	if( $0 ~ /END-EXEC/ && flag != 1 ) { print "TSQCHG MAIN"} }; 1' filename

  #6 (permalink)  
Old 06-11-2007
Registered User
 

Join Date: Jul 2006
Posts: 141
Quote:
Originally Posted by anbu23
Code:
awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print; print "TSQCHG MAIN";next; flag=1}
	if( $0 ~ /END-EXEC/ && flag != 1 ) { print "TSQCHG MAIN"} }; 1' filename


sorry anbu...

i have done a small mistake in giving my requirement...

i wanted "TSQCHG MAIN" to be added before RESP.. not after....
so i have changed the awk u gave as follows..

awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print "TSQCHG MAIN";print; next; flag=1}
if( $0 ~ /END-EXEC/ && flag != 1 ) { print "TSQCHG MAIN"} }; 1' filename


but this inserts at two places...

both before RESP and before END-EXEC...

awaiting ur reply....
  #7 (permalink)  
Old 06-11-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,574
Quote:
Originally Posted by pbsrinivas
sorry anbu...

i have done a small mistake in giving my requirement...

i wanted "TSQCHG MAIN" to be added before RESP.. not after....
so i have changed the awk u gave as follows..

awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print "TSQCHG MAIN";print; next; flag=1}
if( $0 ~ /END-EXEC/ && flag != 1 ) { print "TSQCHG MAIN"} }; 1' filename


but this inserts at two places...

both before RESP and before END-EXEC...

awaiting ur reply....
Move flag statement before to next statement

Code:
awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print "TSQCHG MAIN";print; flag=1; next}
if( $0 ~ /END-EXEC/ && flag != 1 ) { print "TSQCHG MAIN"} }; 1' filename

Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search between pattrens with one string in one or other line........ pbsrinivas Shell Programming and Scripting 12 07-02-2007 03:37 AM
Search between pattrens. pbsrinivas Shell Programming and Scripting 3 05-08-2007 05:34 PM
Need to change a set of lines between two given Pattrens pbsrinivas Shell Programming and Scripting 9 03-22-2007 05:11 AM
how to insert line break + string in vi (search & replace ) umen Shell Programming and Scripting 1 06-08-2006 12:42 PM
sed search and insert apalex Shell Programming and Scripting 1 05-08-2002 12:39 PM



All times are GMT -4. The time now is 08:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0