Operating System - OpenVMS
1753783 Members
6966 Online
108799 Solutions
New Discussion юеВ

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

 
SOLVED
Go to solution
Jim Strehlow
Advisor

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

How can you search files using a search-string with single quote some character single quote?

We have some software programs that generate log files which we must search. The target string includes not just one single quote and some specific character, but: "... 'A' "

How may we avoid DCL string substitution parsing to look for the text string 'A' in several files using the OpenVMS SEARCH command?

Thank you.
19 REPLIES 19
Steven Schweda
Honored Contributor

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

Either I'm dense, or else that wasn't
entirely clear.

What's wrong with this?:

alp $ type apo.txt
abcdefg
abc'defg
abcd'efg
abc'd'efg

alp $ sea a*.txt "'d'"

******************************
ALP$DKA0:[SMS]APO.TXT;1

abc'd'efg

Inside quotation marks (""), you need two
apostrophes ('') to get symbol evaluation.
Steven Schweda
Honored Contributor

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

Are "software programs" anything like
computer programs? (You have some time to
think this over. I need to go to the local
Home Depot now to buy some hardware bolts and
hardware nuts.)
Jim Strehlow
Advisor

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

Steve, I was not as clear as I should have been in my first example. I will try again.

The text log file contains items such as
...A=''B''...
XYZ...B=''C''...
AABBCCDD...A=''D''...
where we must find two adjacent single quotes (apostrophes) a character and then two more adjacent single quotes.

search *.log "A=''D''"
%SEARCH-I-NOMATCHES, no strings matched

because of symbol substitution. I need to turn off symbol substitution.
Jon Pinkley
Honored Contributor

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

$ type test.quot
...A=''B''...
XYZ...B=''C''...
AABBCCDD...A=''D''...
A = "B"
$ sea test.quot """B"""
A = "B"
$ sea test.quot "'"+"'B'"+"'"
...A=''B''...
XYZ...B=''C''...
AABBCCDD...A=''D''...
$

Because the fonts here display two single quotes as if it were a dowble quote, I have attached a text file you can view.
it depends
Jon Pinkley
Honored Contributor

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

I should have stated this in the previous message. The trick I used, is to use three individual strings, none of which contain two successive single quotes, and then use the plus "+" to concatenate the strings.

In other words, to search for all occurrences of two adjacent single quotes, use:

$ search file "'"+"'"

Since this font doesn't display well, that's
it depends
Jim Strehlow
Advisor

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

Getting closer.
The multiple strings that we think would be concatenated appear to be treated individually by search. I get false matches on unwanted lines in the file.


Next attempt:
I use /MATCH=AND to get what I want for now temporarily; but I am not yet understanding why the strings are not combined and treated as one search-string.
It appears that the DCL SEARCH command identically treats the commands
$ search test.quot "'"+"'B'"+"'"/match=and
and
$ search test.quot "'","'B'","'"/match=and

so I am assuming that string concatenation is NOT happening.
Hein van den Heuvel
Honored Contributor

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

teh definition of the problem is still not entriely clear to me. Best I can tell one solution is (on OpenVMS V8.3) :

$ text = "'" + "'%'" + "'"
$ sho symb text
TEXT = "''%''"
$ sea tmp.tmp &text/wild

The & forces 'deferred substitution'.

With PERL on any VMS version the single quotes are still nasty when expressed in a 'one liner'. So I would use 'octal' notation:

$ perl -ne "/\047\047.\047\047/" tmp.tmp


Now if you just want to match on say B and D, not C then change that to :

$ perl -ne "print if /\047\047[BD]\047\047/" tmp.tmp


Cheers,
Hein.


Jim Strehlow
Advisor

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

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

We will be testing version 8.3 on Integrity soon.
Steven Schweda
Honored Contributor

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

If you're looking for a particular character,
and not just any single character, then "&"
seems to help:

alp $ ss = "'"+ "'"+ "d"+ "'"+ "'"

alp $ write sys$output ss
''d''

alp $ sea a*.txt &ss

******************************
ALP$DKA0:[SMS]APO.TXT;2

abc''d''efg

where:

alp $ type apo.txt
abcdefg
abc'defg
abcd'efg
abc'd'efg
abc'defg
abcd'efg
abc'd'efg
abc''defg
abcd''efg
abc'd''efg
abc''d'efg
abc''d''efg