1

I wrote the below code, which will extract the directory name along with the file name and I will use purge command on that extracted Text.

$ sear VAXMANAGERS_ROOT:[PROC]TEMP.LIS LOG/out=VAXMANAGERS_ROOT:[DEV]FVLIM.TXT
$ OPEN IN VAXMANAGERS_ROOT:[DEV]FVLIM.TXT
$ LOOP:
$ READ/END_OF_FILE=ENDIT IN ABCD
$ GOTO LOOP
$ ENDIT:
$ close in
$ ERROR=F$EXTRACT(0,59,ABCD)
$ sh sym ERROR
$ purge/keep=1 'ERROR'

The output is as follows:

ERROR = "$1$DKC102:[PROD_LIVE.LOG]DP2017_TMP2.LIS;27392             "

Problem here is --- Every time the directory length varies (Length may be 59 or 40 or some other value, but the directory and filename length will not exceed 59 characters in my system). So in the above output, the system is also fetching the Version number of that file number. So I am not able to purge the file along with the version number.

%PURGE-E-PURGEVER, version numbers not permitted

Any suggestion -- How to eliminate the version number from the output ?

I cannot use the exact length of the directory, as directory length varies everytime.... :(

  • 2
    Use [`f$parse`](http://h41379.www4.hpe.com/doc/83final/9996/9996pro_111.html) to extract the appropriate parts of the file specification. Or `f$element` to get the part before the semicolon. (A version can be delimited by a semicolon or dot. Sneaky.) Or `f$locate` to get the position of the semicolon for use with `f$extract`. – HABO Aug 21 '17 at 12:41
  • Hi Habo..Could you please tell me how to use F$ELEMENT or F$PARSE in this case... – Aksh Akshay Aug 21 '17 at 14:21
  • 1
    It looks like `f$element( 0, ";", ABCD )` should return everything prior to the semicolon. I don't happen to have a live VMS system handy at the moment. IIRC, `write Sys$Output 'f$element( 0, ";", ABCD )'` will show you the result. – HABO Aug 21 '17 at 19:45
  • Thanks Habo.. It worked for me :) :) :) :) :) – Aksh Akshay Aug 22 '17 at 06:06
  • FWIW: ```$ error_no_version = f$parse(error,,,"device")+f$parse(error,,,"directory")+f$parse(error,,,"name")+f$parse(error,,,"type")``` – user2116290 Aug 22 '17 at 08:18

2 Answers2

2

While HABO explained it, some more explanations

Suppose I use f$search to check if a file exists

a = f$search("sys$manager:net$server.log")

then I find I it exists

wr sys$output a

shows

SYS$SYSROOT:[SYSMGR]NET$SERVER.LOG;9

From the help of f$parse I get

help lex f$parse arg

shows, among other things

`Specifies a character string containing the name of a field in a file specification. Specifying the field argument causes the F$PARSE function to return a specific portion of a file specification.

     Specify one of the following field names (do not abbreviate):

     NODE       Node name
     DEVICE     Device name
     DIRECTORY  Directory name
     NAME       File name
     TYPE       File type
     VERSION    File version number`

So I can do

wr sys$output f$parse(a,,,"DEVICE")

which shows

SYS$SYSROOT:

and also

wr sys$output f$parse(a,,,"DIRECTORY")

so I get

[SYSMGR]

and

wr sys$output f$parse(a,,,"NAME")

shows

NET$SERVER

and

wr sys$output f$parse(a,,,"TYPE")

shows

.LOG

the version is

wr sys$output f$parse(a,,,"VERSION")

shown as

;9

The lexicals functions can be handy, check it using

help lexical

it shows

F$CONTEXT F$CSID F$CUNITS F$CVSI F$CVTIME F$CVUI F$DELTA_TIME F$DEVICE F$DIRECTORY F$EDIT F$ELEMENT F$ENVIRONMENT F$EXTRACT F$FAO F$FID_TO_NAME F$FILE_ATTRIBUTES F$GETDVI F$GETENV F$GETJPI F$GETQUI F$GETSYI F$IDENTIFIER F$INTEGER F$LENGTH F$LICENSE F$LOCATE F$MATCH_WILD F$MESSAGE F$MODE F$MULTIPATH F$PARSE F$PID F$PRIVILEGE F$PROCESS F$READLINK F$SEARCH F$SETPRV F$STRING F$SYMLINK_ATTRIBUTES F$TIME F$TRNLNM F$TYPE F$UNIQUE F$USER

user2915097
  • 30,758
  • 6
  • 57
  • 59
2

The answer with F$ELEMENT( 0, ";", ABCD ) should work, as confirmed. I might script something like this:

 $ ERROR = F$PARSE(";",ERROR) ! will return $1$DKC102:[PROD_LIVE.LOG]DP2017_TMP2.LIS;
 $ ERROR = ERROR - ";"
 $ PURGE/KEEP=1 'ERROR'

Not sure why you have the read loop. What you will get is the last line in the file, but assuming that's what you want.

Mark Diaz
  • 193
  • 1
  • 10