HP OpenVMS Systems

ask the wizard
Content starts here

Text Search and Replace tools?

» close window

The Question is:

 
I have C and Fortran source code that I would like to mo0dify using a text
 search and replace function. I want all the occurances of Apples changed to
 Oranges. Is there a multi file search and replace program that works under
 OpenVMS? I tried copying the
files to an NT system and using a search and replace program there but the
 files that are transferred report an incorrect length to NT and it will not
 work.
Thanks.
 


The Answer is :

 
  Perl, DCL, and occasionally Teco and SUMSLP are the most common tools
  used for this purpose.  Various versions of freeware tools such as awk
  and grep are also available for text searches and text updates on OpenVMS.
 
  Teco:
 
en[MY_DIRECTORY...]*.C$<<ecen$eb^Eq*$:nApples$"s0;'hkek>:g*^A
^A<frOranges$vn$;>>
 
  DCL:
 
$ target = f$edit("apples","UPCASE")
$ replace = "Oranges"
$ wildcard_filespec = "sys$scratch:x.%"
$ close/nolog target_channel
$ close/nolog output_channel
$ target_file = f$search("",1)
$ target_length = f$length(target)
$file_loop:
$ target_file = f$search(wildcard_filespec,1)
$ if target_file .eqs. "" then goto file_done
$ open/read target_channel 'target_file'
$ output_file = target_file - f$parse(target_file,,,"VERSION")
$ open/write output_channel 'output_file'
$record_loop:
$ read/end=record_done target_channel target_record
$replace_loop:
$ match_record = f$edit(target_record,"UPCASE")
$ x = f$locate(target,match_record)
$ y = f$length(target_record)
$ if x .eq. y then goto record_loop
$ prefix = f$extract(0,x,target_record)
$ suffix = f$extract(x+target_length,y-x,target_record)
$ target_record = prefix + replace + suffix
$ write output_channel target_record
$ goto replace_loop
$record_done:
$ close/nolog target_channel
$ close/nolog output_channel
$ goto file_loop
$file_done:
$ close/nolog target_channel
$ close/nolog output_channel
$ exit
 

answer written or last revised on ( 17-JUL-2000 )

» close window