Article View: vmsnet.tpu
Article #118re: How to EDIT files via a COMMAND FIle
From: dectpueve Engineering - the last...
Date: Fri, 20 Nov 1992 20:47
Date: Fri, 20 Nov 1992 20:47
87 lines
4190 bytes
4190 bytes
>>% From: "Frank (Chip) Dyer x9568 ..Electrical Design" <DYERFDF@hsdwl.utc.com
Writes:
> EVE/TPU experts:
>
> I have about 50 files with the number "100C000" (hexadecimal) in them. I
> need to edit all these files and replace "100C000" with "1010000." Is it
> possible to do this through a non-interactive (automatic) process?
>
> Ideally I want to have a COMMAND procedure do a GLOBLAL REPLACE on
> "100C000" - something like
>
> $ EDIT/TPU/NOINIT/NODISplay/COMmand=SYS$INPUT in.src/OUTput=OUT.SRC
> EVE_REPLACE("100A","*!!*!!**")
> $ EXIT
>
> Is this possible? I have never written or used any TPU procedures, so
> any help you can provide will greatly be appreciated. I use EVE quite a
> bit, but as far as writing or using TPU procedures, I have never done
> that.
>
>
> Thanx, Frank
Here ya go:
$! replace_wildcard.com
$!
$! generic replacement com file. Changes every occurance of P3 to P4
$! found in file P1 and writes it out to P2
$!
$! If p3 (the search string) contains a wildcard character ("*"), then
$! P5 contains what characters are to be matched for that wildcard character
$! For example:
$!
$! @replace_wildcard <input-file> <output-file> "export : '*';" -
$! $_ "export : 'V01-123';" "vx1234567890-"
$!
$! would cause the following strings
$! export : '';
$! export : 'Vx001-x55';
$! export : 'V1.0';
$! to be replaced with
$! "export : 'V01-123';"
$!
$ open/write replace_cmd dpl$$build:replace_dpl.tmp
$ write replace_cmd "procedure global_replace (find_pat, repl_str, wild_chars);"
$ write replace_cmd "local found_wildcard,begin_str,end_str,search_pattern,r1;"
$ write replace_cmd "found_wildcard := index (find_pat, ""*"");"
$ write replace_cmd "if found_wildcard = 0"
$ write replace_cmd "then"
$ write replace_cmd " search_pattern := find_pat;"
$ write replace_cmd "else"
$ write replace_cmd " begin_str := SUBSTR (find_pat, 1, found_wildcard-1);
$ write replace_cmd " end_str := SUBSTR (find_pat, found_wildcard+1);
$ !
$ ! Create a pattern that starts with everything up to the wildcard and then
$ ! spans all the characters passed in to the command procedure in p5, then
$ ! ends with what ever follows the wildcard character
$ !
$ write replace_cmd " search_pattern := begin_str + (SPAN (wild_chars) | """") + end_str;"
$ write replace_cmd "endif;"
$ write replace_cmd "position (beginning_of (current_buffer));"
$ write replace_cmd "loop"
$ write replace_cmd " r1 := search_quietly (search_pattern, forward, no_exact);"
$ write replace_cmd " if r1 = 0 then return; endif;"
$ write replace_cmd " position (r1);"
$ write replace_cmd " erase (r1);"
$ write replace_cmd " copy_text (repl_str);"
$ write replace_cmd "endloop;"
$ write replace_cmd "endprocedure;"
$ write replace_cmd "!"
$ write replace_cmd "b1 := create_buffer (""b1"", get_info(command_line,""file_name""));"
$ write replace_cmd "position (b1);"
$ write replace_cmd "global_replace (""''P3'"", ""''P4'"", ""''p5'"");"
$ write replace_cmd "write_file (b1, get_info(command_line, ""output_file""));"
$ write replace_cmd "quit (off, 1); "
$ close replace_cmd
$ EDIT/TPU/NODISP/NOSECT/NOINIT/COMMAND=replace_wildcard.tmp -
/output='P2 'P1
$ !
********************************************************************************
Brian J. McCarthy - DECTPU/EVE Development Project Leader
Digital Equipment Corp, Nashua, NH
********************************************************************************
Technical Details
Message-ID:
<9211202047.AA07837@enet-gw.pa.dec.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!news.service.uci.edu!unogate!mvb.saic.com!simpact!inland!cmkrnl!infopiz!mccall!info-tpu-newsgate!listShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!news.service.uci.edu!unogate!mvb.saic.com!simpact!inland!cmkrnl!infopiz!mccall!info-tpu-newsgate!list Newsgroups: vmsnet.tpu Subject: re: How to EDIT files via a COMMAND FIle Message-ID: <9211202047.AA07837@enet-gw.pa.dec.com> From: dectpu/eve Engineering - the last of a dying race 20-Nov-1992 1545 Date: Fri, 20 Nov 92 12:47:49 PST Reply-To: DECTPU/EVE Engineering - the last of a dying race 20-Nov-1992 Organization: The Internet Return-Path: <TPU-Mgr@SHSU.edu> Errors-To: TPU-Mgr@SHSU.edu X-Listname: Text Processing Utility (TPU) Language Discussion List Apparently-To: info-tpu@shsu.edu Lines: 87