Article 146618 of comp.os.vms:
In Article <31901C63.339@dsm.po.my> K C Lim <kclim@dsm.po.my> writes:
>Hi,
>
>I am just wondering if VMS editors like EDT or EVE can be made to run in Batch 
>mode. What I need is to use the editor to replace certain strings in a text
>file with other strings. There are other stuffs that need to be done too but
>I won't mention it to keep it simple. As this is a daily process, I thought
>it would be nice if I could automate this whole process. 
>
>Anyone for any suggestions??
>
>TIA.
>KC Lim

Here is another batch TPU procedure that will do Global Search Replace (GSR)
and Global Line Delete (GLD).  I call it gsrgld.template and edit it to
some_other_name.com when I edit it for a particular job that has to be done.
I hope this helps.

Ed James                       Manager, Computer & Communications Services
Lockheed Martin Laboratories   Internet james@mml.mmc.com
1450 South Rolling Road        Voice    410-204-2042
Baltimore MD, 21227-3898       Fax      410-204-2115

$! gsrgld.template	Global Search Replace & Global Line Delete via tpu
$
$!Ed James                       Manager, Computer & Communications Services
$!Lockheed Martin Laboratories   Internet james@mml.mmc.com
$!1450 South Rolling Road        Voice    410-204-2042
$!Baltimore MD, 21227-3898       Fax      410-204-2115
$
$ set verify			! if you want to watch
$
$				! set up gsrgld command
$ gsrgldx :== edit/tpu/nosect/nodisp/comm=gsrgldx.tmp
$
$ set def sys$login:		! set default to wherever file(s) are located:
$
$ create gsrgldx.tmp		! create tpu command file
! Use this TPU initialization file as follows:
!
!  -> Change strings in calls to global_search_replace and
!       global_line_delete located below marked "Insert changes here:".
!
!  -> Run via command line:
!       $ edit/tpu/nosect/nodisp/comm=gsrgldx.tmp [/OUTPUT=out_name] file_name

! Perform search through current buffer and delete any
!  line that contains input string.

procedure global_line_delete (patx)

local src_range, replacement_count, msg_text;

! Return to caller if string not found
on_error
    if error = tpu$_strnotfound then
         msg_text := fao ('Done. !UL line!%S deleted.', replacement_count);
         message (msg_text);
    else
         if error = tpu$_endofbuf then
              msg_text := 
                   fao ('Done. !UL line!%S deleted.', replacement_count);
              message (msg_text);
         endif;
    endif;
    return;
endon_error;

replacement_count := 0;

loop
    src_range := search (patx, forward);  ! Search returns a range if found
    if src_range <> 0 then
         position (src_range);
         erase_line;
         replacement_count := replacement_count + 1;
    endif;
!    src_range := search (patx, forward); ! Search returns a range if found
!    if src_range <> 0 then
!         erase_line;
!         replacement_count := replacement_count + 1;
!    endif;
endloop;
endprocedure

! Perform search through current buffer and replace any
!  input string.

procedure global_search_replace (str_or_pat, str2, eggsact)

! Perform search through current buffer and replace a pattern or
!  string with a new string

local src_range, replacement_count, msg_text;

! Return to caller if string not found
on_error
    msg_text := fao ('Completed !UL replacement!%S', replacement_count);
    message (msg_text);
    return;
endon_error;

replacement_count := 0;

loop
    ! Search returns a range if found
    if eggsact = 'EXACT' then
        src_range := search (str_or_pat, forward, exact);
    else
        src_range := search (str_or_pat, forward, no_exact);
    endif;
    erase (src_range);
    position (end_of (src_range));
    copy_text (str2);
    replacement_count := replacement_count + 1;
endloop;
endprocedure

! Executable statements

eve$x_null := '';		! Null string
input_file := get_info (command_line, 'file_name');
main_buffer := create_buffer ('main', input_file);
output_file_name := get_info (command_line, 'output_file');
if output_file_name <> eve$x_null then
    input_file_name_only :=
        file_parse (input_file, eve$x_null, eve$x_null, name) +
        file_parse (input_file, eve$x_null, eve$x_null, type);
    parsed_output_file_name :=
        file_parse (output_file_name, 'sys$disk:[]', input_file_name_only);
    if parsed_output_file_name <> eve$x_null then
        set (output_file, main_buffer, parsed_output_file_name);
    endif;
endif;

!*******************************************************************
! example commands
!*******************************************************************
!
!    define a pattern to be replaced by some string
!
!pat := line_begin & 'DEFINE';
!position (beginning_of (main_buffer));
!global_search_replace (pat, 'REDEFINE', 'EXACT');
!
!    define a pattern to be replaced by some string
!
!pat := line_begin & 't'
!position (beginning_of (main_buffer));
!global_search_replace (pat, 'T', 'EXACT');
!
!    replace some text string with another text string
!
!position (beginning_of (main_buffer));
!global_search_replace ("INSERT 'FARWCOMM'", "INCLUDE 'FARWCOMM.FOR'", 'EXACT');
!
!    replace some text string with another text string
!
!position (beginning_of (main_buffer));
!global_search_replace ("a", "x", 'NO_EXACT');
!
!    delete all lines containing some string
!
!position (beginning_of (main_buffer));
!global_line_delete (' WD TIMESTAMP');
!
!    replace string with string (strings do not have to be printable)
!
!position (beginning_of (main_buffer));
!global_search_replace ("<ESC>", ascii(27), 'EXACT');     !esc
!
!position (beginning_of (main_buffer));
!global_search_replace (ascii(12), eve$x_null, 'EXACT');  !ff
!
!position (beginning_of (main_buffer));
!global_search_replace (ascii(13), eve$x_null, 'EXACT');  !cr
!
!position (beginning_of (main_buffer));
!global_search_replace (ascii(10), eve$x_null, 'EXACT');  !lf
!
!position (beginning_of (main_buffer));
!global_search_replace (ascii(00), eve$x_null, 'EXACT');  !null
!
!    delete all lines containing some string
!
!position (beginning_of (main_buffer));
!global_line_delete ('.if gopher');
!
!    delete all lines containing some string
!
!position (beginning_of (main_buffer));
!global_line_delete ('.else gopher');
!
!    delete all lines containing some string
!
!position (beginning_of (main_buffer));
!global_line_delete ('.endif gopher');
!
!    delete all lines containing some string
!
!position (beginning_of (main_buffer));
!global_line_delete ('<>');
!
!*******************************************************************
! Insert actual commands below --v
!*******************************************************************
!
crlf := ascii(13) + ascii(10);
position (beginning_of (main_buffer));
global_search_replace (ascii(10), crlf, 'EXACT');  !lf to crlf
!
!*******************************************************************
! Insert actual commands above --^
!*******************************************************************

write_file (main_buffer);
quit;
$
$ gsrgldx sys$login:lf.tmp			! run the tpu commands
$
$ delete /nolog gsrgldx.tmp;*			! delete tpu command file
$
$ exit						! finish





