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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search between pattrens with one string in one or other line........
# 8  
Old 06-06-2007
[QUOTE=aigles]Comments are already ignored.



I have Something of this sort which fails

I2OCR *PROCEDURE DIVISION USING XXXXXX
PROCEDURE DIVISION
*******CHANGE FOR ENDS*******
USING
*******CHANGE FOR BEGINS*******
AAAA
BBBBB
CCCC
DDDD
EEEE
FFFF
GGGG
.
# 9  
Old 06-06-2007
Quote:
Originally Posted by pbsrinivas
Comments are already ignored.

I have Something of this sort which fails

I2OCR *PROCEDURE DIVISION USING XXXXXX
PROCEDURE DIVISION
*******CHANGE FOR ENDS*******
USING
*******CHANGE FOR BEGINS*******
AAAA
BBBBB
CCCC
DDDD
EEEE
FFFF
GGGG
.
My awk script assume that comments lines start with * as first non blank character. That is not the case for your file since the comment line start with I2OCR.
I have modified my awk program to remove from input lines all chars from the first * to the end of line.
Code:
#!/usr/bin/awk -f
# Awk File : cbl_args.awk

function print_args_count() {# Function for printing filename and arguments count 
   if (file)                 # Only if file name is set.
      print file," #Args=" args_count;
}

FNR==1  {              # New input file
   print_args_count();       # Print argument count for previus file
   file         = FILENAME;  # Memorize the file name
   proceed_args = 0;         # Reset flag 'USING' keyword found, args coming..
   args_count   = 0;         # Reset arguments count
}

{                            # For all input lines
   sub(/\*.*$/, "");         # Removes comments (all chars from first * to end of line)
}

/PROCEDURE DIVISION/,/\./ {  # For lines from 'PROCEDURE DIVISION' to '.'
   count = NF;               # Argument count in line set to fields count
   if (/PROCEDURE DIVISION/) # If 'PROC. DIV.' 
      count -= 2;            #   PROC. and DIV. aren't arguments
   if (/USING/) {            # If 'USING'
      proceed_args=1;        #   set flag 'USING', args coming..
      --count;               #   'USING' is'nt an argument
   }                         #
   if (NF == ".")            # If final point alone (not 
      --count;               #   '.' isn't an argument
   if (proceed_args)         # If flag arguments coming set
       args_count += count;  #   add new arguments found in the line
}

END {                        # All input files have been read
   print_args_count();       # Print argument count for last file
}

Jean-Pierre.

Last edited by aigles; 07-02-2007 at 04:11 AM..
# 10  
Old 06-06-2007
I have modified my awk program to remove from input lines all chars from the first * to the end of line.


but still the this file give as

7.cob #Args=8


7.cob----
I2OCR *PROCEDURE DIVISION USING XXXXXX
PROCEDURE DIVISION
*******CHANGE FOR ENDS*******
USING
*******CHANGE FOR BEGINS*******
AAAA
BBBBB
CCCC
DDDD
EEEE
FFFF
GGGG
.
# 11  
Old 06-06-2007
Modify the following statement :
Code:
   if ($NF == ".")            # If final point alone

Jean-Pierre.
# 12  
Old 06-06-2007
Quote:
Originally Posted by aigles
Modify the following statement :
Code:
   if ($NF == ".")            # If final point alone

Jean-Pierre.


Thanks a lot Jean-Pierre

Its works great.....
# 13  
Old 07-02-2007
Hi

I am using the awk Script developed by Jean-Pierre

I need a small modification in the Script.....

This time i am searching form the Call to the Particular Program with USING + Agruments...

Let me be clear

Input is

PERFORM AAAA-CALL-PROGRAM.
AAAA-CALL-PROGRAM.
CALL 'PROGRAM' USING CCCCC
DDDDD.

In Input i search for CALL 'PROGRAM' and See How many Arguments are Passed to it...
IN this case it 2..

I tried Modifying the Script as follows

/.*[ ]*CALL.*'\''PROGRAM/,/\./ {
count = NF;
if (/.*[ ]*CALL.*'\''PROGRAM/) # If CALL PROGRAM
count -= 2; # CALL and PROGRAM aren't arguments
if (/USING/) {
proceed_args=1;
--count;


But this Gives me

temp #Args=0 even if i have two args CCCCC and DDDDD..

Is Suppose some Problem in my Pattern matching.. I used '\'' to search for '(Single Quote)

I wanted to match if the Called Program and the Calling Program use the Same Number of Arguments... for that I was trying this script..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

2. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

3. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

4. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

7. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

8. 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

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