|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 |
|
|
|
|||
|
Code:
awk ' /WRITEQ/,/END-EXEC/ { if ( $0 ~ /RESP/ ) {print; print "TSQCHG MAIN";next}}; 1' filenameCode:
sed "/WRITEQ/,/END-EXEC/{/RESP/s/$/\\
TSQCHG MAIN/;}" filenameLast edited by anbu23; 06-11-2007 at 03:11 AM.. |
|
|||
|
Quote:
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 |
|
|||
|
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".... |
|
|||
|
Quote:
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 |
|
|||
|
Quote:
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.... |
|
|||
|
Quote:
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |