Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

search for a specific string

 
SOLVED
Go to solution
nipun_2
Regular Advisor

search for a specific string

Hi,
I have OpenVMS 7.3-2

My question:
I want to read a person's name from the file header.

My approach:
I do a simple search command
$search File.EXT "Name" /out=Name.txt

It's fine but what this gives me (obviously) is the the entire line

Name: BOBBY DING DDSDFD SDDFSD

Now what I need is Bobby Ding from this, the distance between the ":" and B is always 18 so for any of the files the name always starts after 18 character space but the end varies
So my question is can we get just the name

Bobby Ding in a symbol eg

alpha := Bobby Ding

Let me know your thoughts and comments
4 REPLIES
Ian Miller.
Honored Contributor
Solution

Re: search for a specific string

could this help?
http://h71000.www7.hp.com/freeware/freeware80/extract/
____________________
Purely Personal Opinion
Hein van den Heuvel
Honored Contributor

Re: search for a specific string

>> Let me know your thoughts and comments

Read up topic 876934

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=876934

And learn perl !

$ perl -ne "if (/^Name:\s+(\w+\s+\w+)/){ $ENV{NAME}=$1; last }" tmp.tmp
$ show log name
"NAME" = "BOBBY DING" (LNM$PROCESS_TABLE)

If you don't care about first vs last match then:

$ perl -ne "$ENV{NAME}=$1 if /^Name:\s+(\w+\s+\w+)/" tmp.tmp


As 'bonus' the regexpr will only trigger on lines that start with the "Name". That may help. Drop the "^" if Name: can float on the line. Or use /^\s*name\s*:\s+(\w+\s+\w+)/i

That insists name is the first word on a line and must be followed by a colon, but allows for any whitespace and any case.

Enjoy,
Hein.


Hein van den Heuvel
Honored Contributor

Re: search for a specific string


And just because I wanted to know how hard a pipe solution would really be:

$ pipe sea tmp.tmp "Name:" | (read sys$pipe x ; y=f$ed(x,"COMPRESS") ; s=" " ; x=f$el(1,s,y)+s+f$el(2,s,y) ; def/job x &x)
$
$ show log x
"X" = "BOBBY DING" (LNM$JOB_819E9000)

Hein.

Craig A Berry
Honored Contributor

Re: search for a specific string

I just wanted to point out that there are a couple of different ways to use Perl but also set DCL symbols rather than logical names if that's what you need or prefer.

In the following example, I use Hein's Perl code verbatim, but before running it I tell Perl to use DCL symbols rather than logical names for its built-in %ENV hash:

$ define PERL_ENV_TABLES CLISYM_GLOBAL
$ perl -ne "if (/^Name:\s+(\w+\s+\w+)/){ $ENV{NAME}=$1; last }" tmp.tmp
$ show symbol name
NAME == "BOBBY DING"

If you want local symbols rather than global, use CLISYM_LOCAL as the value of PERL_ENV_TABLES.

Or here's a little hack that uses the VMS::DCLsym extension that's been included with every Perl distribution of the last 10 years or so (and in this example bypasses the documented tied hash inteface and directly uses the internal _setsym method rather than setsym):

$ perl -"MVMS::DCLsym" -ne -
_$ "if (/^Name:\s+(\w+\s+\w+)/){ VMS::DCLsym::_setsym('NAME',$1,'GLOBAL'); last }" tmp.tmp
$ show symbol name
NAME == "BOBBY DING"