Search between pattrens.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search between pattrens.
# 1  
Old 05-08-2007
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

END-IF

YYYYY
BBBBBB


I want to get everything between "EXEC CICS DELETEQ TS" and 2nd END-IF ...

Is it Possible...???

SO my output for previous File would be everyting upto YYYYY starting from EXEC CICS DELETEQ TS
# 2  
Old 05-08-2007
A awk solution a little bit more complex ...
Code:
function print_lines() {
   for (i=1; i<=line_count; i++) {
      if (i <= end_line) print lines[i];
      delete lines[i];
   }
   line_count = 0;
   end_line   = 0;
   inside     = 0;
}
/"EXEC CICS DELETEQ TS"/ {
   print_lines();
   inside = 1;
}
inside {
   lines[++line_count] = $0;
   if (/END-IF/) end_line=line_count;
}
END {
   print_lines();
}


Jean-Pierre.
# 3  
Old 05-08-2007
Quote:
Originally Posted by aigles
A awk solution a little bit more complex ...
Code:
function print_lines() {
   for (i=1; i<=line_count; i++) {
      if (i <= end_line) print lines[i];
      delete lines[i];
   }
   line_count = 0;
   end_line   = 0;
   inside     = 0;
}
/"EXEC CICS DELETEQ TS"/ {
   print_lines();
   inside = 1;
}
inside {
   lines[++line_count] = $0;
   if (/END-IF/) end_line=line_count;
}
END {
   print_lines();
}


Jean-Pierre.


I have used it in the following manner

awk -f awkscript inpFile

If thats Right i find output to be NULL...
# 4  
Old 05-08-2007
Removes quotes in EXEC pattern :
Code:
/EXEC CICS DELETEQ TS/ {

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

YouTube: Search Engine Optimization | How To Fix Soft 404 Errors and A.I. Tales from Google Search

Getting a bit more comfortable making quick YT videos in 4K, here is: Search Engine Optimization | How To Fix Soft 404 Errors and A.I. Tales from Google Search Console https://youtu.be/I6b9T2qcqFo (0 Replies)
Discussion started by: Neo
0 Replies

2. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

3. What is on Your Mind?

Search Results (Search, New, and Today's Topics) Animation Switch

Hey, I added an animation switch on the search results page; so by default the thread previews are off, but if you want to look at them, just click on the green button and the thread previews will turn on (and back off). See image and attached animation: ... (1 Reply)
Discussion started by: Neo
1 Replies

4. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

5. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

6. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

7. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 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

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 ... (9 Replies)
Discussion started by: pbsrinivas
9 Replies
Login or Register to Ask a Question