1

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.

Kevin Bedell
  • 13,254
  • 10
  • 78
  • 114
BobbyA
  • 2,090
  • 23
  • 41
  • 1
    Does `HELP SEARCH` do anything for you? Use `/OUTPUT` to write the results to a file, then `OPEN` and `READ` it. Or, for a more reliable method, just `OPEN` and `READ` the source file and parse each line into `ID` and `DIRECTORY` after skipping the first line. Be polite and `CLOSE` when you're done. – HABO Jun 28 '12 at 03:50
  • http://www.bing.com/search?q=dcl+vms+manual – John Saunders Jun 28 '12 at 04:30
  • @user92546 IMHO Your comment could be an answer. – Luc M Jun 28 '12 at 13:27
  • @LucM - Could be an answer, but I still don't have a question. Is this a one time quicky search or something that needs to be run repeatedly? Console output for a human interpeter or something that can be reliably processed further? Homework assignment that requires using DCL commands, not utilities, and at least 10 vowels? I can't tell from the OP. – HABO Jun 28 '12 at 15:00

2 Answers2

1
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

Hein
  • 1,453
  • 8
  • 8
  • 1
    The pointy brackets aren't part of the log files, but this got me on the right track, thank you! For anyone googling around for this in the future, the following might be of use: F$EDIT, F$LENGTH, F$EXTRACT, F$LOCATE, F$ELEM (F$EDIT has several arguments that help with getting rid of white space) – BobbyA Jun 29 '12 at 20:13
  • Upvote for "substring" to extract fields. This is what the OP was asking. Finding the record was a foregone conclusion. – mckenzm Feb 04 '15 at 19:30
1

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

vmsnomad
  • 319
  • 2
  • 7