We have many command procedures, and we need to make a global modification in all of them (one particular string need be replaced by a different string). Is there an elegant method of accomplishing this without having to individually edit each and every one of them.
Thanks,
Chaim
Note: If you are the author of this question and wish to assign points to any of the answers, please login first.For more information on assigning points ,click
here
I normally take a buffer in EVE in which all files are listed that need modif. Then I use LEARN to get the file, do the change and save it. Then replay it "number of files" times.
Very handy since any edit session can be done (but keep in mind that the edits must be applicable to all source files). If it goes wrong, delete/sin will save you.
HP engineering has released the FIND kit (via freeware V7.0, see VMS site). Beside just FIND it has also FIND/REPLACE, which works quite well (incl. regular expressions).
this is a kitfile for the PCSI utility on VMS. The PCSI Utility (Commandverb PRODUCT) is used to install, reconfigure... software products on VMS. It replaced the older VMSINSTAL DCL-procedure. The doc-set contains more information about PCSI.
You should transfer this file onto your VMS system in binary mode. To install the FIND utility pls. issue:
$ PRODUCT INSTALL FIND
and answer any questions. This will install the FIND utility onto the default destination SYS$COMMON.
If the file attributes have been corrupted during transfer, you may repair them with $ SET FILE <name of kit>/ATT=(RFM=FIX,LRL=512,MRS=512)
I have always used (a variation of) Hein's DCL. It's quick, it's easy, it's foolproof.
One note of caution: please make sure of a good to-be-replaced string. You will NOT want to replace some substring that happens to match!
If you want to make sure, extend the DCL with a DIFF/OUTP=<in some new tmp dir> after each EDIT(default: the highest 2 existing versions are compared) Scan the DIFF output files for any UNintended changes (expect none or very few of those).
Before you embark on editing, think about what you're changing and why. There may be a mechanism that means you don't need to modify any code, OR, if you must change code, you may be able to do it in such a way that future changes are much simpler.
Is the string a command (can be redefined as a symbol) or file name (might be possible to redefine as a logical name)?
If it's something that DCL won't automatically substitute, you may be able to code it so there's a manual substitution. Maybe something like this?
$ ChaimString=F$TRNLNM("ChaimStringValue") $ IF ChaimString.EQS."" THEN ChaimString="DefaultValue"
... $ COMMAND 'ChaimString'
Now you can change the string value by defining the logical name ChaimStringValue.
Perl is not the answer to everything, but it can make system managers and system programmer much more efficient. For VMS based folks perl is also a great way to make themselves more valuable for non-VMS tasks (Unix, Windoze,...)
At this point each VMS system should have Perl installed IMHO (and DFU also :-).
btw... if I did write a dcl script, or a perl soltuion, I woudl probably first test whether the string is present before creating a fresh version with no changes. In may example that could look like:
$ if p1.eqs."" then exit $ wild = p1 - "*" - "%" $ loop: $ file = f$searc(p1) $ if file.eqs."" then exit $ search/nowarn/noout 'file noot $ if $severity.eq.3 then goto skip_edit $ editx/edt/com=sys$input: 'file s/noot/aap/%wh exit $skip_edit: $ if p1.nes.wild then goto loop
Personally, I use the TECO editor, which can be programmed to iterate through one or more directories, performing each change globally within a file.
The advantage of TECO, which is admittedly cryptic (unless one is used to its syntax) is that it comes as part of the base OpenVMS distribution kit on all versions of OpenVMS. Thus, it is useable without worrying about installing additional software.
Personal I use 2 com files: one searches for a particular string that needs to be changed, and one to do the actual change. It shows the string found, and you can say yes or no to change that file; afterwards a difference is shown. Edit/edt or TECO is used to do the actual change; TECO sometimes needs a temporary files to do so.
Change_all_files.com $! VERANDER ALLE FILES $LOOP: $ FILE=F$SEARCH("''P1'",3) $ IF "''FILE'" .EQS. "" THEN $ EXIT $ NAME=F$PARSE(FILE,".COM","","name") $ F_TYPE=F$PARSE(FILE,".COM","","TYPE") $ F_dir=F$PARSE(FILE,".COM","","DIRECTORY") $ F_device=F$PARSE(FILE,".COM","","Device") $ write sys$output name,F_TYPE $ zoek_string="check_devices.com" $ if "''p2'" .nes. "" then $ zoek_string="''p2'" $ SEA 'f_device''f_dir''NAME''F_TYPE' "''zoek_string'" $ ERROR_CODE :== '$STATUS' $ IF ERROR_CODE .EQS. "%X08D78053" THEN GOTO LOOP $ if f$extract(0,6,name) .eqs. "CHANGE" then goto loop $ INQUIRE ANS "Moet file ''f_device'''f_dir'''NAME'''F_TYPE' gedaan worden N/[J] ?" $ IF ANS .EQS. "N" THEN GOTO LOOP $ SET NOON $@sys$login:CHANGE_FILES 'f_device''f_dir''NAME''F_TYPE' $ GOTO LOOP ---------------------------------- change_files.com *ht$$ $! COMMAND FILES OM backup COM FILES TE UPDATEN met de laatste check_devices $ FILE="''P1'" $! maak de .tec file om uit te voeren $ open /write file update_backups.tec $ write file "eb''file'$" $ write file "a$" $ write file "ncheck_devices.com$0l$" $ write file ".,zk$ercheck_devices.com$" $ write file "ex$$" $ close file $! teco = "edit\/teco" $! teco /execute=update_backups.tec $! of de bovenste of de onderste twee commando's uitvoeren $! ASSIGN SYS$COMMAND SYS$INPUT $ edit/edt 'file' s/RECOVERY_DATA-/RECOVERY_DATA -/wh exit $ SET NOON $ TEST_1=F$SEARCH("''FILE';-1") $ SET ON $ IF "''TEST_1'" .NES. "" THEN $ DIF 'FILE'
Please re-reply with the attachment renamed to ".txt"
This silly Internet Exploder comes back with "To help protect your security, Internet Explorer blocked this site from downloading files to your computer...."
Here's another search and replace tool that uses DCL and TPU in one command file (see attached TXT file). Unless you want CYA files and an output file from the TPU search, I would modify the file to your desires.
In general, the command line could be:
$ @Replace P1 P2 P3 [EXACT]
where: P1 = the desired device-dir-file-ext (s) P2 = (optional quoted) string to search for P3 = (optional quoted) string as replacement P4 = Optional - EXACT, to tell TPU to search for the exact string to find or replace with so using quotes around P2 &/or P3 is required