Search code examples
openvmsdcl

OpenVMS - DELETE Line if TEXT like x


I have a batch script that is writing all files inclusive of path and version number to a TMP file for a physical device. This batch script then writes any lines that demonstrate a file version number greater than a provided variable.

DIRECTORYX := DIRECTORY /NODATE /NOHEADING /NOTRAILING
DIR_OUTPUT_FILENAME = "TOPAS$UTILLOG:" + F$UNIQUE() + ".TMP"
DEVICE = $1$DGA1112
DIRECTORYX 'DEVICE':[000000...]*.*;* /NOSIZE /OUTPUT='DIR_OUTPUT_FILENAME'

At the same time I have files to which I am not interested in being reported back to me. In this case i want to remove any lines that potentially contain this filename (filename.ext;) fromt he TMP file so that the batch script can continue through it and only report files that i dont explicity want to ignore.

How would I go about reading the file while inside a loop using 'IGNORE_FILE' as the variable for the text string to match and remove the associated line of text so that when my batch script proceeds through the file it will not report files requested to be ignored.

Many Thanks for any help


Solution

  • Allright... Now I see where you coming from.

    How would i write everything from the 7th , to end of line?

    Well, you could just loop starting with i=7, or you could use a "quote" the string and use the quote as new separator. Here is an example with both, using a double-quote as almost natural second separator choice

    $
    $ READ SYS$INPUT BUFF
    SHG101,$1$DGA1101:,25,15,10,5000,100,X.TMP,Y.DAT
    $
    $ excludes = ""
    $ tmp = F$ELEMENT(7, ",", BUFF)
    $ IF tmp.NES.","
    $ THEN
    $   i = 8
    $   excludes = tmp
    $exclude_loop:
    $   tmp = F$ELEMENT(i, ",", BUFF)
    $   IF tmp.NES.","
    $   THEN
    $      excludes = excludes + "," + tmp
    $      i = i + 1
    $      GOTO exclude_loop
    $   ENDIF
    $   excludes = "/EXCLUDE=(" + excludes + ")"
    $ ENDIF
    $
    $ SHOW SYMB excludes
    $
    $! Using a different delimitor:
    $ READ SYS$INPUT BUFF
    SHG101,$1$DGA1101:,25,15,10,5000,100,"X.TMP,Y.DAT"
    $
    $ excludes = ""
    $ tmp = F$ELEMENT(1, """", BUFF)
    $ IF tmp.NES."," THEN excludes = "/EXCLUDE=(" + tmp + ")"
    $
    $ SHOW SYMB excludes
    

    In the code we see: Checking ''DEVICE' for high file versions (>= ;''HVERNO') - may take some time...>

    I urge you to check out DFU The big loop code "READ FH3 /END_OF_FILE=LABEL$_EOF_DIRLIST1 BUFF2..." will simplify to:

    dfu searc/versio=min=200'excludes'form="!AS"/out=tmp.tmp dka0:
    

    This will run in seconds almost no matter how many files. Toss the whole warning stuff, include it always checking for 32000 as it is (almost) free. After executing the DFU command, create the 'fancy' output if tmp.tmp is not empty by creating your header, and appending tmp.tmp. Always delete tmp.tmp ($ CLOSE/DISP=DELETE )

    Free advice...

    Those 15 deep nested IF-THEN-ELSE-ENDIF to pick up a message looks terrible (to maintain) Consider an array lookup ?! Here is a worked out example:

    $! prep for test
    $ EL = p1
    $ EL_DIAG = "FILE.DAT"
    $ LOCAL_STATUS = "12345"
    $
    $! Code snippet to be tested
    $
    $ x  = 'EL'
    $ ! Fold multiple conditions into 1 message
    $
    $ if  (EL .EQ. 7) .OR. (EL .EQ. 14) .OR. (EL .EQ. 21) .OR. (EL .EQ. 25) -
                    .OR. (EL .EQ. 29) .OR. (EL .EQ. 30)  THEN x = "L1"
    $
    $ MSG_6     = "error opening "       + EL_DIAG + " for WRITE (RM=" + LOCAL_STATUS + ")"
    $ IDT_6     = "OPENIN"
    $ MSG_L1    = "error reading from "  + EL_DIAG + " (RM=" + LOCAL_STATUS + ")"
    $ IDT_L1    = "READERR"
    $ MSG_8     = "device name missing " + EL_DIAG
    $ IDT_8     = "DNNF"
    $
    $ ! Pick up the required texts
    $
    $ IF F$TYPE(MSG_'x').EQS.""
    $ THEN
    $   WRITE SYS$OUTPUT "No message found for code: ", EL
    $   EXIT 16
    $ ENDIF
    $
    $ MSG   = MSG_'x
    $ IDTXT = IDT_'x
    $
    $ WRITE SYS$OUTPUT "MSG  : ", MSG
    $ WRITE SYS$OUTPUT "IDTXT: ", IDTXT
    

    Cheers, Hein