From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 30-MAY-1989 10:45
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Re: Edits of multiple files?

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Sun, 28 MAY 89 16:37:23 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Sun, 28 May 89 16:18:08 PDT
Received: by ucbvax.Berkeley.EDU (5.61/1.36)
	id AA23166; Sun, 28 May 89 16:17:05 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 29 May 89 06:38:21 GMT
From: munnari!csv!dougcc@uunet.uu.net  (Douglas Miller)
Organization: Computer Services, Victoria College, Melbourne
Subject: Re: Edits of multiple files?
Message-Id: <119@csv.viccol.edu.au>
References: <8905270310.AA04657@ucbvax.berkeley.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <8905270310.AA04657@ucbvax.berkeley.edu>,
MIKE@UCDHEP.BITNET (Mike Hannon; UCD Physics; [916]-752-4966) writes:
> Every once in a while one of the users here has a need to make the same
> editing changes in a number of different files.  E.g., it might be necc.
> to change the string "FOO" to the string "BAR" in FILE1.TXT, FILE2.TXT,
> and FILE3.TXT.

The following simple TPU program can do this.  To process the above example
you would type:

   $ EDIT/TPU/NOSECTION/NODISPLAY/COMMAND=REPLACE FILE%.TXT
   old string: FOO
   new string: BAR

and the substitution will be made in each of the three files.



------ REPLACE.TPU -------- (cut here) ---------------------------------

PROCEDURE pat_replace (oldstring, newstring)
   LOCAL range2, count ;
   position (beginning_of (current_buffer)) ;
   count := 0 ;
   LOOP
      range2 := search_quietly (oldstring, FORWARD, EXACT) ;
      EXITIF range2 = 0 ;
      position (beginning_of (range2)) ;
      erase (range2) ;
      copy_text (newstring) ;
      count := count + 1 ;
      ENDLOOP ;
   IF (count > 0) THEN
      message (fao('Replaced "!AS" !UL time!%S with "!AS"',
         oldstring, count, newstring)) ;
   ENDIF ;
ENDPROCEDURE ;

old_string := read_line ("old string: ") ;
new_string := read_line ("new string: ") ;
filename := GET_INFO (COMMAND_LINE, 'file_name') ;
LOOP
   exp_filename := FILE_SEARCH (filename) ;
   EXITIF exp_filename = "" ;
   mainbuffer := CREATE_BUFFER (exp_filename, exp_filename) ;
   position (mainbuffer) ;
   pat_replace (old_string, new_string) ;
   IF get_info (mainbuffer, "modified") THEN
      write_file (mainbuffer)
   ELSE
      message ('No changes made.') ENDIF ;
   delete (mainbuffer) ;
   ENDLOOP ;
quit ;

