!From: "Ed James 410-204-2042 james@mml.mmc.com" !Subj: Global search and replace on multiple files !Date: Thu, 4 May 1995 8:38:30 -0400 (EDT) ! !Attached is a small tpu procedure that contains two procedures, !global_line_delete and global_search_replace that I got somewhere over ten !years ago. Enjoy. ! !Ed James Manager, Computer & Communications Services !Martin Marietta Laboratories Internet james@mml.mmc.com !1450 South Rolling Road Voice 410-204-2042 !Baltimore MD, 21227-3898 Fax 410-204-2115 ! !$ set verify !$ gsrgldx :== edit/tpu/nosect/nodisp/comm=gsrgldx.tmp !$ set def sys$login: !$ create gsrgldx.tmp ! 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; !******************************************************************* ! Insert changes here: ! pat := line_begin & 'DEFINE'; position (beginning_of (main_buffer)); !global_search_replace (pat, 'REDEFINE', 'EXACT'); !position (beginning_of (main_buffer)); !global_search_replace ("a", "x", 'NO_EXACT'); !position (beginning_of (main_buffer)); !global_line_delete (' WD TIMESTAMP'); !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 !position (beginning_of (main_buffer)); !global_line_delete ('.if gopher'); !position (beginning_of (main_buffer)); !global_line_delete ('.else gopher'); !position (beginning_of (main_buffer)); !global_line_delete ('.endif gopher'); !position (beginning_of (main_buffer)); !global_line_delete ('<>'); !******************************************************************* !write_file (main_buffer); quit; !$ gsrgldx sys$login:jl_holdings_data.old !<<< change to file to be editted !$ delete /nolog gsrgldx.tmp;* !$ exit