Sponsored Content
Top Forums Shell Programming and Scripting Search between pattrens with one string in one or other line........ Post 302120433 by aigles on Wednesday 6th of June 2007 12:18:13 PM
Old 06-06-2007
Quote:
For the Second case i have added a line (May be wrong)

/PROCEDURE DIVISION/,/\./ {
if ($0 ~ /USING/) {
proceed_args=1;
next;
}
if ($0 ~ /^[[:space:]]*\./) next;
if ($0 ~ /^[[:space:]]*\*/) next; (Thought it will skip for "*")
if (proceed_args && NF>0) ++args_count;
}
Comments are already ignored.


Quote:
Sorry

but small change ..

there is also a case where we have

PROCEDURE DIVISION USING AAA BBB. (In this case it Fails)
I have rewritten the central part of the awk program to handle all cases (i hope) :
Code:
#!/usr/bin/awk -f
# Awk File : cbl_args.awk

function print_args_count() {
   if (file) print file," #Args=" args_count;
}

FNR==1  {
   print_args_count();
   file         = FILENAME;
   proceed_args = 0;
   args_count   = 0;
}

/^[[:space:]]*\*/ {
   next; # skip comment
}

/PROCEDURE DIVISION/,/\./ {
   count = NF;
   if (/PROCEDURE DIVISION/) count -= 2;
   if (/USING/) {
      proceed_args=1;
      --count;
   }
   if (NF == ".") --count;
   if (proceed_args) args_count += count;
}

END {
   print_args_count();
}

and add some modifications to my input files and create new ones :
Code:
$ cat pgm3.cbl
*
PROCEDURE DIVISION
USING

AAA BBB
CCC
.
*

$ cat pgm4.cbl
PROCEDURE DIVISION USING AAA BBB CCC DDD.
$ cat pgm5.cbl

PROCEDURE DIVISION USING
    AAA
    BBB
    CCC
    DDD
    EEE. 
$

The output :
Code:
$ awk -f cbl_args.awk pgm*.cbl
pgm0.cbl  #Args=0
pgm1.cbl  #Args=1
pgm2.cbl  #Args=2
pgm3.cbl  #Args=4
pgm4.cbl  #Args=4
pgm5.cbl  #Args=5
$

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
GO::Model::GeneProduct(3pm)				User Contributed Perl Documentation			       GO::Model::GeneProduct(3pm)

NAME
GO::Model::GeneProduct - gene product in a particular species DESCRIPTION
represents a gene product in a particular species (this will effectively always be refered to implicitly by the gene symbol even though a gene may have >1 product) acc Usage - Returns - Args - symbol Usage - Returns - Args - type Usage - Returns - Args - full_name Usage - Returns - Args - as_str Usage - Returns - Args - add_synonym synonym_list accessor: gets/set list of synonyms [array reference] speciesdb Usage - Returns - Args - add_seq Usage - Returns - Args - GO::Model::Seq seq_list Usage - Returns - GO::Model::Seq listref Args - seq Usage - Returns - GO::Model::Seq Args - returns representative sequence object for this product properties Usage - Returns - hashref Args - hashref set_property Usage - $sf->set_property("wibble", "on"); Returns - Args - property key, property scalar note: the property is assumed to be multivalued, therefore $sf->set_property($k, $scalar) will add to the array, and $sf->set_property($k, $arrayref) will set the array get_property Usage - Returns - first element of the property Args - property key get_property_list Usage - Returns - the property arrayref Args - property key to_fasta Usage - Returns - Args - returns the longest seq by default perl v5.14.2 2013-02-07 GO::Model::GeneProduct(3pm)
All times are GMT -4. The time now is 07:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy