Operating System - OpenVMS
1753481 Members
4215 Online
108794 Solutions
New Discussion юеВ

Re: How to extract string from command output?

 
SOLVED
Go to solution
Duncan Morris
Honored Contributor

Re: How to extract string from command output?

Andrew, you are using the wrong operator for comparison

.LE. 4 Arithmetic less than or equal

.LES. 4 String less than or equal

Try replacing .LES. with .LE. when working with numbers.
Jan van den Ende
Honored Contributor

Re: How to extract string from command output?

Andrew,

On the risk of being superfluous, some more explicit explanation of Duncans answer:

If you compare the STRING 5 with 123456, then it compares the first character of both, if equal the next char, etc, until a difference is found. And since "5" is greater than "1", so the string "5" is considered greater than "12345".

Sorry if this was already clear.

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Andrew Yip
Advisor

Re: How to extract string from command output?

Hello Duncan & Jan,

Oops! Thanks for spotting the mistake.
I now realized using the wrong operator.
It works now. =)

By the way, if i were to search a file for a particular string and the result is negative, how do i get the empty result or status or whatever which i can work on?

E.g.
$ search temp.txt ABC /output=line.txt
%SEARCH-I-NOMATCHES, no strings matched

I need the result to perform some work. However if the search result is positive, at least i have something to retrieve from the 'line.txt' file to perform some work.

Is there any work-around solution to this?
Please advice, anyone. Thanks a million!

Andrew
Jan van den Ende
Honored Contributor

Re: How to extract string from command output?

Andrew,

your easiest pathway to achieve that is to do any search that results in "no strings matched".
_DIRECTLY_ after that do a
$ show symbol $status
Pick up the result and paste it into your command file.
In your command file, if for some reason it is undesirable or impossible to IMMEDIATELY act upon $STATUS, then start by saving it in another symbol, and use that later on.
Take care, the value of $status actually is in STRING format, so you need the string comparison operators.

Success.

Proost.

Have one on me.

jpe



Don't rust yours pelled jacker to fine doll missed aches.
John Abbott_2
Esteemed Contributor

Re: How to extract string from command output?

Hi Andrew,

The search command still generates a file, an emtpy one. From Wim's first post of code, the first read will result in an end-of-file detection and therefore the code will jump to e30: label.

If you want to do something else you could check the $severity level returned from the search command:

For %SEARCH-I-NOMATCHES, no strings matched
$SEVERITY == "3"

for matches
$SEVERITY == "1",

so after the search command line you could add $ IF $SEVERITY .EQS. "3" THEN ...

If course $STATUS could also be used and checked. ($SEVERITY and $STATUS return information about the previous DCL command executed, ie their level of success and return code, try typing $ write sys$output f$message($status) after entering an invalid dcl command)

Also, you could add the qualifer /NOWARNINGS to the search command to hide the "%SEARCH-I-NOMATCHES, no strings matched" message from appearing.

Kind Regards
John.
Don't do what Donny Dont does
Hein van den Heuvel
Honored Contributor

Re: How to extract string from command output?

Andrew,

Maybe it is time to review the task you are trying to accomplish and perhaps provide a sample input file, appended as .TXT to a reply.

The VMS SEARCH tool would be good to select a few lines to a new /intermediate output file.
But it looks like you needs data from several lines, and interpret each line.
In that case I would just read teh whole file with DCL and pick and choose as you go.

Then again, I would not really do that in DCL but in PERL instead.

Based on the text line presented earlier i would write a perl program like:

--- freespace.pl ------
while (<>) {
$main = $1 if /MAIN Memory.*\s(\d+)/;
$VSM = $1 if /Memory free.*\s(\d+)/;
$int = $1 if /Program fil.*\s(\d+)/;
$pat = $1 if /Pattern fil.*\s(\d+)/;
}
$problem .= " Main" if ($main < $int);
$problem .= " Pattern" if ($VSM < $pat);
$ENV{freespace} = $problem;
--------------------

And I would use it in a DCL procedure like:

$PERL freespace.pl your-file.txt
$IF F$TRNLNM("freespace").NES.""
$THEN
$ WRITE SYS$OUTPUT "Insufficient tester memory space! (", F$TRNLNM("freespace"), ")"
$ GOTO ERROR34
$ ELSE write temp "Free space check OK."
$ ENDIF


fwiw,
Hein.
Robert_Boyd
Respected Contributor

Re: How to extract string from command output?

Here is another way to do this with PIPE and SEARCH:

This example shows how to get the begin and end dates for an errorlog file into a logical name and then into a symbol:

$ SUMMARIZE = "DIAGNOSE/TRANSLATE/SUMMARY"
$ pipe summarize 'errlog_file' | search sys$input 'date_string' | -
( read sys$pipe d1 ; read sys$pipe d2 ; -
ds=""""+f$ele(dtelem," ",f$edi(d1,"TRIM,COMPRESS"))+","+f$ele(dtelem," ",f$edi(d2,"TRIM,COMPRESS"))+"""" ; -
define/job errdates &ds )
$SYMBOL_ASSIGN:
$ errdates = F$trnlnm("ERRDATES")
$ deassign/job ERRDATES
$ 'start_symbol' == f$element(0,",",errdates)
$ 'end_symbol' == f$element(1,",",errdates)

Master you were right about 1 thing -- the negotiations were SHORT!
Andrew Yip
Advisor

Re: How to extract string from command output?

Hello Jan & John,

Thanks a million!
Your suggestions solves my problem.
It's a pretty good and fast idea.

But, by the way, out of curiousity, does the $status: "%X00000001" & "%X08D78053" mean anything specifically besides 'found' & 'not found'?
=)

Andrew
Andrew Yip
Advisor

Re: How to extract string from command output?

Hello Hein,

Thanks for your help & advice rendered earlier in this post, and thanks for promoting Perl too.

As much as i would like to pick up Perl, but i have limited time and resources to do so now.

Very much for now, i'm pretty stuck with using OVMS to deal with some modifications on my existing scripts. =(

But anyway, you guys are real great! Couldn't have done it without all of you!
You guys made my day!

Andrew
Andrew Yip
Advisor

Re: How to extract string from command output?

Hmm..with regards to my earlier question on how to extract a line from 1 file and replace it on the same line of another line, i'm still having some doubts.

Though Kalle had earlier suggested to use the EXTRACT utility, but i'm sorry i hadn't really tried it out yet.

But anyway, i stumbled upon the open/read/write command which claims to be able to open a file and write records at the beginning of the file, as compared to EOF for the open/append command.

However, when i tried to use this, i was given an error which i believe i must have done it wrongly. Stupid me!
What's the correct way to use the open/read/write command?