Question

How do I search text in a file with DCL? Yes, I have to use DCL.

The file format is straight forward:

<NUMBER OF ENTRIES>
<ID>  <DIRECTORY>
<ID>  <DIRECTORY>
.
.
.
<ID>  <DIRECTORY>

They're separated by a few white space characters. I just need to search the file for a given ID and extract the DIRECTORY.

It's a really simple task, but I can't seem to find any decent DCL documentation anywhere.

Was it helpful?

Solution

Edited.... the forum 'eats' strings like <xx> unless marked as code.    

Are there pointy brackets on the datalines or not? Please provide a REAL example is it or: XX XXX-DIRECTORY

I am assuming the first.

VMS as it ships does NOT have a standard tool to select a field from a record. But there are a bunch of standard tools available for OpenVMS which can do this. Mostly notably (g)AWK and PERL So that's what I would use:

$ gawk /comm="$1 == ""<xx>"" { print $2 }" tmp.tmp
<xxx-DIRECTORY>

or

$ perl -ne "print $1 if /^\s*<xx>.*?<([^>]*)/" tmp.tmp
xxx-DIRECTORY

Those can be augmented for case-and-space-sensitivity, as needed and trim that <> as needed. And maybe you need the search ID to be a parameter or not.

Anyway, in a pure DCL script it could look like....

$ IF p2.eqs."" then exit 16
$ CLOSE/NOLOG file
$ OPEN/READ file 'p1
$loop:
$ READ/END=done file rec
$ id = F$EDIT( F$ELEM(0,">",F$ELEM(1,"<",rec)), "UPCASE")
$ IF id.NES.p2 THEN  GOTO loop
$ dir = F$ELEM(0,">",F$ELEM(2,"<",rec))
$ WRITE SYS$OUTPUT dir
$ GOTO loop
$done:
$CLOSE/NOLOG file

if the <> do not exist, use this for core...

$ rec = F$EDIT(rec,"TRIM,COMPRESS")
$ id = F$EDI(F$ELEM(0," ",rec),"UPCASE")
$ IF id.NES.p2 THEN  GOTO loop
$ dir = F$ELEM(1," ",rec)

And the perl would be:

$ perl -ne "print $1 if /^\s*<xx>\s+(\S+)/" tmp.tmp

Good luck Hein

OTHER TIPS

Alternatively, if the ID field looks like fixed-width, then you may convert the file to RMS INDEXED , keyed on ID field. Then you can just do lookup by calling READ/KEY='ID'.

Call HELP on CONVERT , READ /KEY and perhaps SEARCH /KEY

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top