Operating System - OpenVMS
1822727 Members
3772 Online
109644 Solutions
New Discussion юеВ

Global replace for many command procedures...?

 
SOLVED
Go to solution
ChaimBu
Frequent Advisor

Global replace for many command procedures...?

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
23 REPLIES 23
Wim Van den Wyngaert
Honored Contributor

Re: Global replace for many command procedures...?

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.

Wim
Wim
Karl Rohwedder
Honored Contributor
Solution

Re: Global replace for many command procedures...?

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).

regards Kalle
ChaimBu
Frequent Advisor

Re: Global replace for many command procedures...?

Kalle,

Could you please place a link to the VMS site as I am not yet familiar with this.

Thanks,

Chaim
Karl Rohwedder
Honored Contributor

Re: Global replace for many command procedures...?

ChaimBu
Frequent Advisor

Re: Global replace for many command procedures...?

Kalle,

Thanks!

Please excuse my "ignorance". I downloaded this to my PC. WHat is this file? How do I use it on the VMS system?

Thanks,

Chaim
Karl Rohwedder
Honored Contributor

Re: Global replace for many command procedures...?

Chaim,

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 /ATT=(RFM=FIX,LRL=512,MRS=512)

regards Kalle
Joseph Huber_1
Honored Contributor

Re: Global replace for many command procedures...?

.PCSI$COMPRESSED files are distributions for the PCSI utility, THE PRODUCT command.

To install the software, use the command
PRODUCT INSTALL FIND
See HELP PRODUCT for /SOURCE and /DESTINATION switches.

The file must have been transferred in BINARY mode (by HTTP download or FTP IMAGE mode).
http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: Global replace for many command procedures...?

A global replace command using no extra program , but EDIT/EDT came from Ph.Helbig once upon a time, I edited a bit, here it is:

http://wwwvms.mppmu.mpg.de/util_root/com/gsr.com

http://www.mpp.mpg.de/~huber
Hein van den Heuvel
Honored Contributor

Re: Global replace for many command procedures...?


So many solutions...

Using basic DCL scripting it could be done as:

------- edit_many.com -------
$ if p1.eqs."" then exit
$ wildcard_removed = p1 - "*" - "%"
$ loop:
$ file = f$searc(p1)
$ if file.eqs."" then exit
$ editx/edt/com=sys$input: 'file
s/noot/aap/%wh
exit
$ if p1.nes.wildcard_removed then goto loop


Personally I would grab perl, mostly because I never bothered to learn tpu.

I find that the regular expressions in perl are so much more desirabel to find just the right strings to replace.

Here is a perl 'one liner' for the same edit:

$ perl -p -i -e "s/old-text/new-text/g" %.tmp

-p = 'print after loop" : loop over input file stashing into default variable $_, print $_ to sys$ouput after executing perl program over each line.

-i = 'inplace' : output to same name as input

-e = 'execute this' : program text follows

s/x/y/g : no variable listed -> operate on $_, s = substitute, g = all matches on line.


Enjoy,
Hein.
Jan van den Ende
Honored Contributor

Re: Global replace for many command procedures...?

Chaim,

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= 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).

Success.

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
John Gillings
Honored Contributor

Re: Global replace for many command procedures...?

Chaim,

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.
A crucible of informative mistakes
ChaimBu
Frequent Advisor

Re: Global replace for many command procedures...?

Hein,

I assume that the perl command assumes that there is perl on the VMS system. In our case, we do NOT have perl.

Thanks,

Chaim

Hein van den Heuvel
Honored Contributor

Re: Global replace for many command procedures...?

Hey... you started it. You wrote 'elegant'

:-)

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

Cheers,
Hein.

Robert Atkinson
Respected Contributor

Re: Global replace for many command procedures...?

Similar command procedure (attached) that we've used for years.

Rob.
Robert Gezelter
Honored Contributor

Re: Global replace for many command procedures...?

Chaim,

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.

- Bob Gezelter, http://www.rlgsc.com
Ruud Dijt
Advisor

Re: Global replace for many command procedures...?

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'


Peter Barkas
Regular Advisor

Re: Global replace for many command procedures...?

Just in case you don't yet have enough solutions, here is a command procedure that may be useful:

http://dcl.openvms.org/search.php?query=sars&what=stories&limit=100
Bernd Fischer_3
New Member

Re: Global replace for many command procedures...?

Chaim,

just to add my .05 Cent (Euro): We're using the attached piece of TPU-Programming for years.

Regards

Bernd
Hein van den Heuvel
Honored Contributor

Re: Global replace for many command procedures...?

Bernd,

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...."

Now you and I know that's a crock, but I guess we'll just have to play the game and mis-label the data, no matter how much I hate that.
[See my rant earlier today in:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1031169
:^]
Jan van den Ende
Honored Contributor

Re: Global replace for many command procedures...?

Hein,

I tried to read that, but

This page has been removed.


:-(

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Tony_289
Advisor

Re: Global replace for many command procedures...?

Chaim,

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

Regards,

Tony



Tony_289
Advisor

Re: Global replace for many command procedures...?

I had an issue with HP passport, so lets try to attach the DCL command file (in TXT format).

-- Tony
Bernd Fischer_3
New Member

Re: Global replace for many command procedures...?

Sorry,

forgot about the .COM-issue. Renamed version is attached.

Bernd