Operating System - OpenVMS
1829494 Members
1467 Online
109991 Solutions
New Discussion

Re: Find and replace the word

 
amit27k
New Member

Find and replace the word

I have to write a script to find different word in a file and replace all the words into a sequential array.
3 REPLIES 3
Heinz W Genhart
Honored Contributor

Re: Find and replace the word

Hi amit27k

welcome to the ITRC Forum.

Could you supply some more information. Maybe you could post a part of your file and explain what you want to exchange.

regards

Geni
Hein van den Heuvel
Honored Contributor

Re: Find and replace the word

Hello amit,

Welcome to the OpenVMS ITRC Forum.

>> I have to write a script to find different word in a file and replace all the words into a sequential array.

Please explain to us WHY you have to do this and perhpas WHICH TOOLS are at your disposal.

What is a 'word' in you world? (any combination of characters outside whitespace?)
What is a sequential array in your world?
(In my world an array is a memory structure, for you perhaps just an other flat file ?)

'Replace' in my world means to put something in the place of something else. So when we find a word, what will be replaced?

What problem are you trying to solve?
- world hunger?
- a homework question?
- a serious business problem?

perl -ne "chomp; $w{$_}++ foreach split /\W+/} {print qq($w{$_}:$_\n) foreach (sort keys %w)" login.com

Regards,
Hein.
John Gillings
Honored Contributor

Re: Find and replace the word

Is this a global substitute? Here's a DCL solution using TPU

$ IF p1.EQS."" THEN INQUIRE p1 "Word to be replaced"
$ IF p2.EQS."" THEN INQUIRE p2 "Word to replace it with"
$ IF p3.EQS."" THEN INQUIRE p3 "File to replace it in"
$ ws="WRITE SYS$OUTPUT"
$ PIPE ws "EVE_GLOBAL_REPLACE(""''p1'"", ""''p2'"");" | -
EDITX/TPU/NODISPLAY/COMMAND=SYS$PIPE: 'p3'
$ EXIT
A crucible of informative mistakes