1829122 Members
1879 Online
109986 Solutions
New Discussion

DCL Search

 
SOLVED
Go to solution
Kenneth Toler
Frequent Advisor

DCL Search

I am trying to create a text file searching multiple fortran files. I want to see each time OPEN,WRITE,READ,CALL AND CLOSE occurs in this order for each file. The command I am using is:

search [...]*.for;*
" open(","write","read","call","close(" /output=results.txt

Why does the results.txt file not have the order I searched in above? For example, all of the "write" statements appear in one part of the text file and the "read" statements occur in another part of the text file. I want the results.txt file to display in sequential order: " open(","write","read","call","close(" as it occurs in the fortran file.

Can anyone help me resolve this problem?

6 REPLIES 6
John Abbott_2
Esteemed Contributor
Solution

Re: DCL Search

Hi Kenneth,

Does this help ? Tested locally as much as poss, but please check. Assumes you don't have more than 16K worth of files to search.

Hopefully the DCL formatting will remain correct when I post this.

J.

$TOP:
$ FILE=F$SEARCH("[...]*.for;")
$ IF FILE .EQS. ""
$ THEN CREATE RESULTS.TXT;
$ APPEND RESULT.TXT;* RESULTS.TXT;
$ DELETE/NOCONFIRM RESULT.TXT;*
$ EXIT
$ ENDIF
$ OPEN/WRITE O RESULT.TXT;
$ WRITE O "Searching file ''FILE'..."
$ CLOSE O
$ SEARCH/NOWARNING 'FILE' "OPEN(","WRITE","READ","CALL","CLOSE("/OUTPUT=RESULT.TXT
$ GOTO TOP
Don't do what Donny Dont does
Robert Gezelter
Honored Contributor

Re: DCL Search

Kenneth,

The SEARCH utility searches for the specified strings in the file(s). It does not work with any relationships between the specified strings, with the exception of the logical operations specified with the /MATCH qualifier.

What you appear to be attempting to do is also subtler than you think, in terms of how many source modules are not written in the "obvious" sequence.

I would suggest using the output of SEARCH as guidance to a manual examination of the source files. Files which contain NONE of the keywords specified can be ignored on a first pass.

- Bob Gezelter, http://www.rlgsc.com
Robert_Boyd
Respected Contributor

Re: DCL Search

Hi Kenneth,

I'm wondering if you could explain what it is you want to do with the results once you get them? It may be there is another way to solve your problem.

In order to get the structured search output you are wanting, you'll have to do seperate searches for each string and concatenate the results.

The search utility will list all records in the order found containing any of the search items in a 1-pass scan through the file(s). See Bob Gezelter's comments.

If you could explain what you hope to do with the output and how this will help you solve a particular problem it might be easier to make suggestions.

Robert
Master you were right about 1 thing -- the negotiations were SHORT!
labadie_1
Honored Contributor

Re: DCL Search

If you are familiar with awk, it is available with Tcpip 5.any, cleverly hidden.

awk :== $ SYS$COMMON:[SYSHLP.EXAMPLES.TCPIP.snmp]gawk

awk

%GAWK-W-FILE_RQRD, missing required element: data_file
(use "SYS$INPUT:" to read data lines from the terminal)

usage: GAWK /COMMANDS="awk program text" data_file[,data_file,...]
or GAWK /INPUT=awk_file data_file[,"Var=value",data_file,...]
or GAWK /INPUT=(awk_file1,awk_file2,...) data_file[,...]

options: /FIELD_SEPARATOR="FS_value"
- /VARIABLES=("Var1=value1","Var2=value2",...)
- /LINT /POSIX /[NO]STRICT /VERSION /COPYRIGHT /USAGE
- /OUTPUT=out_file

Or maybe you will want to use some regex, so

- install Perl, which is available on Vms at
http://www.sidhe.org/vmsperl/

- install Python, which is available at vmspython.dyndns.org
Sheldon Smith
HPE Pro

Re: DCL Search

Add the "/head" qualifier so you see each file in which Search finds the desired strings.

Note: While I am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company

Accept or Kudo

Hein van den Heuvel
Honored Contributor

Re: DCL Search


This works for me, but needs fine tuning for you.

--------- search.pl -----------------
$wild = shift @ARGV;
$wild =~ s/"//g;
$list = shift @ARGV or die "Usage: $0 ".'"""""" ';
@words = split /,/,$list;
while ($file = glob $wild) {
print "\n\n--- $file ---\n\n";
open (FILE,"<$file") or die "failed to open $file for input";
@lines = ;
foreach $word (@words) {
print foreach (grep (/$word/i, @lines));
}
}

1) grab a wildcarded filespec passed in triple double-quotes.
2) remove remaining double quotes
3) grab comma-seperated word-list
4) stick words into an array
5) walk on the wild side
6) identify current file
7) open current file
8) slurp file into memory array
9) loop over words
10) grep for each words and print if found (case insensitive)
-------------------------------
perl search.pl """*.c""" open,read,write


Now that quoting is ugly and needed to prevent perl from helping.
The alternative is to swap the list and the wildcard around on the command line and let perl expand:

---------- search_2.pl -----------
$list = shift @ARGV or die "Usage: $0 ";
@words = split /,/,$list;
while ($file = shift @ARGV) {
print "\n\n--- $file ---\n\n";
open (FILE,"<$file") or die "failed to open $file for input";
@lines = ;
foreach $word (@words) {
print foreach (grep (/$word/i, @lines));
}
}


-------------
perl search_2.pl open,read,write *.c


Hope this helps,

Hein.