Operating System - OpenVMS
1753768 Members
5567 Online
108799 Solutions
New Discussion юеВ

Re: search command search-string - how search for '<char>' ?

 
SOLVED
Go to solution
Hoff
Honored Contributor
Solution

Re: search command search-string - how search for '<char>' ?

Massively Brute Force:

$ x="**A**"
$ x[0,8]=%x27
$ x[8,8]=%x27
$ x[24,8]=%x27
$ x[32,8]=%x27
$ search y.y &x
....Z=''A''...
ABC=''A''...
$ type y.y
....Z=''A''...
...A=''B''...
XYZ...B=''C''...
AABBCCDD...A=''D''...
ABC=''A''...
$

Ampersand-based symbol substitution has been around only slightly less than forever. It's a second phase of substitution within the DCL parsing processing -- and you can get a double symbol substitution this way, if you need to do that. You can substitute a substring into a variable, then substitute the variable itself. This is one (very brute-force) way you can implement DCL arrays.

The 2nd edition of the Writing Real Programs in DCL book does cover ampersand-based substitution as it is one of the few ways to substitute symbols within the DCL command PIPE and its related processing.

Jon Pinkley
Honored Contributor

Re: search command search-string - how search for '<char>' ?

Well I blew it in my haste to get my answer in. I tested the setting of a symbol, and if I had paid attention to the output of the example I gave, I would have seen it was matching more than intended. I was trying to avoid the use of a temporary symbol, but now I am wondering if it is possible to do without the use of & and a temporary symbol.

It appears that the concatenation is being done by DCL, at a later stage than the CLI handling routines.

So it appears that Hein's example is about as short as is possible (that I know of).

If you need to search for a general string enclosed by two single quotes, you can set a temporary symbol using one of the methods mentioned, concatenating strings with single quotes, or overlaying an existing string with binary values as Hoff demonstrated. Once the string is in the symbol, using deferred substitution allows the symbol to escape the first pass substitution, but still be passed to the program as the "substituted" value.

For example to find xyzzy

$ tmp = "'"+"'xyzzy'"+"'"
$ search file &tmp

By the way, the new feature Hein was referring to was the /WILD switch, not the "&" deferred substitution. He was saying that if you were always searching for two single quotes followed by a single character and then two more single quotes, you could use the % "match single character" wildcard along with the new /WILD switch (and the &) to do it.

As Hoff said, the & substitution has been around since very early days.

Try this:

$ a="&B" ! B must be uppercase
$ b="C" ! C must be uppercase
$ c="Hello"
$ write sys$output 'a
Hello
$

If you understand why that works, you will be well on your way to understanding DCL parsing.

P.S. I tend to avoid the use of & substitution because it is almost guaranteed to confuse the next person to visit the command procedure. There are also some seemingly arbitrary restrictions, for example the need for the symbols to be in uppercase. Try the above example with lowercase characters in the quotations, and you will see that it does not work.

However, there are cases where they are required, Hoff mentioned a few, and it seems to me that this is another case where they are necessary.
it depends
Hoff
Honored Contributor

Re: search command search-string - how search for '<char>' ?

Here's a variation of what I've used with the escape character and control sequences -- non-printable, so it doesn't work so well when entering it in editors and such -- and worse, you don't generally want to have a control sequence interpreted other than at procedure run-time -- which can be used here:

$ apost ="*"
$ apost[0,8] = %x27
$ string = apost + apost + "A" + apost + apost

Hein van den Heuvel
Honored Contributor

Re: search command search-string - how search for '<char>' ?

>> Thank you for the "heads up" regarding some new string substitution feature.

Jim, as others pointed out, and the other examples make clear, the substitution feature has always been there.

The /WILD is newish, but since you did not indicate a specific version I though it was safe to assume you were running the current version. Reasonable? :^)

Anyway... the V8.3 Alpha SEARCH.EXE image runs just fine on a V7.2-1 Alpha. I tried.
Of course you need to provide the appropriate command definition which you can get from an 8.3 box with the VERB freeware, or find it attached here. I changed the original to point to image SEARCH_V83 to keep it clear and clean.

Finally, you did not react to the PERL suggestion. If you are really serious about searching for interesting pattern, than a langue providing REGULAR EXPRESSIONS is the way to go IMHO. For OpenVMS that would be PERL or AWK. Well worth the short learning curve. Not need to get all caried away with objects and methods, just exploit the basic tools like regexpr's.

Regards,
Hein.
Jon Pinkley
Honored Contributor

Re: search command search-string - how search for '<char>' ?

I agree with Hein that learning Perl or Awk is worthwhile. They allow for more complex pattern matching than SEARCH.

The primary advantage of being able to do it in DCL is portability to other VMS systems that may or may not have other tools loaded.

The techniques discussed to allow DCL to set symbols with doubled single quotes is still useful however. Where I have used it is in command procedures that generate other command procedures, where the generated command procedure has a line like

$ mail nla0: "''notify'" /subject="Entry ''this_entry' starting ''this_proc'"

The generating command procedure would have a line like:

$ write outproc "$ mail nla0: ""'"+"'notify'"" /subject=""Entry '"+ -
"'this_entry' starting '"+"'this_proc'"""

P.S. Hein, I don't know how to do the following with regex:

$ seach file a,b,c,d,e/match=and

without testing for each permutation of ordering. Am I missing something simple?
it depends
Ian Miller.
Honored Contributor

Re: search command search-string - how search for '<char>' ?

See also freeware FIND utility which does pattern matching.

http://h71000.www7.hp.com/freeware/freeware70/find/
____________________
Purely Personal Opinion
Hein van den Heuvel
Honored Contributor

Re: search command search-string - how search for '<char>' ?

>> $ seach file a,b,c,d,e/match=and
>> without testing for each permutation of >> ordering. Am I missing something simple?

regular expressions are 'pattern matches', not the dcl searched.
So I'm afraid you need to either do the permutations if practical or combine them. For example:
/a/ && /b/ && /c/ && /d/ && print

fwiw.
Hein.


Jon Pinkley
Honored Contributor

Re: search command search-string - how search for '<char>' ?

Thanks Hein, that works.

$ sea sys$login:login.com b,c,x,p,g,2/mat=and
$ mgbook4 :== $utility:mgbook disk$axpdocsep962:[decw$book]*lib*/sh
$ awk "/b/ && /c/ && /x/ && /p/ && /g/ && /2/ { print }" sys$login:login.com
$ mgbook4 :== $utility:mgbook disk$axpdocsep962:[decw$book]*lib*/sh

$

I was under the mistaken impression that only one pattern was allowed.
it depends
Sebastian Bazley
Regular Advisor

Re: search command search-string - how search for '<char>' ?

By the way, Perl one-liners can include multiple consecutive single-quotes if one uses back-slash to protect the second single quote:

perl -ne "print if m('\'D'\')" tmp.tmp

Still a bit messy, but easier than using octal escapes.

[The qq() and q() notation can also be useful in VMS one-liners]
Jim Strehlow
Advisor

Re: search command search-string - how search for '<char>' ?

Hoff did it again.

I am not yet a PERL user. (One of these days.)

I have been around since VMS v3 and have forgotten about using & in such a way.
I do so much database work with PL/SQL I sometimes forget some DCL basics.

We have some 7.1-2 customers, 7.2-1, 7.3, 7.3-1 etc. but we use 8.2 and just installed 8.3 on Integrity.

Thank you one and all.