Article View: vmsnet.tpu
Article #144Re: HELP!! String search and replace
From: Rob Young
Date: Thu, 28 Jan 1993 08:04
Date: Thu, 28 Jan 1993 08:04
131 lines
5711 bytes
5711 bytes
In <1993Jan28.025042.7651@seq.uncwil.edu> hawks@seq.uncwil.edu writes:
To do what you are after you could put a wrapper on the following
.com like so:
$ loop:
$ nextfile = f$search("*.*")
$ if nextfile .eqs. "" then exit
$ device = f$parse(nextfile,,"device")
$ direct = f$parse(nextfile,,"directory")
$ filename = f$parse(nextfile,,"name")
$ ftype = f$parse(nextfile,,"type")
$ allpieces = device + direct + filename + ftype
$ @replace_wildcard 'nextfile' 'allpieces' oldstring newstring
$ goto loop
The above is meant as an example. I am unable to spawn out of this crazy
newsreader and so can't test what is above. What I am attempting to
do is create a higher version of the same file.
From an earlier post, thanks to Brian McCarthy. Very good
little piece of TPU. One thing, note the dpl$$build needs to
be replaced.
---- Begin earlier post -----
From: dectpu/eve Engineering - the last of a dying race 20-Nov-1992 1545
Newsgroups: vmsnet.tpu
Subject: re: How to EDIT files via a COMMAND FIle
Message-ID: <9211202047.AA07837@enet-gw.pa.dec.com>
Date: 20 Nov 92 20:47:49 GMT
Reply-To: DECTPU/EVE Engineering - the last of a dying race 20-Nov-1992
>>% 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
********************************************************************************
---- End earlier post -----
young@tattoo.cs.widener.edu
"He's got a force field and a flexible plan He's got a date with fate
in a black sedan. He plays fast forward as long as he can. But he won't
need a bed -- He's a DIGITAL man." -- Neil Peart
Technical Details
Message-ID:
<1k842dINN32v@cs.widener.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!ukma!cs.widener.edu!cs.widener.edu!usenetReferences:
<1993Jan27.022647.21209@seq.uncwil.edu> <1k5t24INN2ei@gap.caltech.edu> <1993Jan28.025042.7651@seq.uncwil.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ukma!cs.widener.edu!cs.widener.edu!usenet From: YOUNG@tattoo.cs.widener.edu (Rob Young) Newsgroups: vmsnet.tpu Subject: Re: HELP!! String search and replace Date: 28 Jan 1993 08:04:29 GMT Organization: Widener News/Mail Gateway Lines: 131 Distribution: world Message-ID: <1k842dINN32v@cs.widener.edu> References: <1993Jan27.022647.21209@seq.uncwil.edu> <1k5t24INN2ei@gap.caltech.edu> <1993Jan28.025042.7651@seq.uncwil.edu> NNTP-Posting-Host: tattoo.cs.widener.edu X-News-Reader: VMS NEWS 1.20 In-Reply-To: hawks@seq.uncwil.edu's message of Thu, 28 Jan 1993 02:50:42 GMT