Operating System - OpenVMS
1753288 Members
5835 Online
108792 Solutions
New Discussion юеВ

Re: Can you do a F$EXTRACT on a PIPE output

 
Hein van den Heuvel
Honored Contributor

Re: Can you do a F$EXTRACT on a PIPE output

>> I should have mentioned I wanted it to loop.

Then you can not just use a 'one liner'.
You'll need a helper command file, or a better programming language.


For example, with tmp.com being
-----
$open/read pipe sys$pipe
$loop:
$read/end=done pipe rec
$write sys$output f$ext(37,17,rec)
$goto loop
$done:
----------
$ pipe search/match=and tmp.tmp 8148, 5.00 | @tmp

I suppose you could generate the helper on the fly, and delete. I sometimes 'embed' it in the main procedure, calling itself with a label to jump to.

------ $!test.com
$if p1.nes."" then goto 'p1
$pipe ... | @'f$env("procedure") print_it
:
$exit
$print_it:
$open/read ...
$loop:
$ ...
$goto loop
--------

But if you go that route, why not have the DCL script do the loop/search?
(Possible answer... too much data to process efficiently by DCL )

-----
$close/nolog tmp
$open/read tmp tmp.tmp
$loop:
$read/end=done tmp rec
$if f$len(rec).eq.f$loc("8148",rec) .or. f$len(rec).eq.f$loc("5.0",rec) then goto loop
$write sys$output f$ext(37,17,rec)
$goto loop
$done:
$close tmp
-------------

Or just using perl:

$ perl -lne "print $1 if /5.00\s+(8148.{10})/" tmp.tmp


But surely that little table is not the end goal.
And possible those 5.0 and 8148 are not really string constants.
So what are the prior and next steps?
What is the real problem you are trying to solve?

pipe's may or might not be useful in solving the real problem.
Perl or awk may or might not be more useful

Hein
John Gillings
Honored Contributor

Re: Can you do a F$EXTRACT on a PIPE output

Niall,

PIPE is great, but can often get too convoluted to be worthwhile. Pipe stages through command procedures to write more complex code.

You'd think that doing everything in memory would outperform writing to disk, but counterintuitively, PIPE is usually MUCH slower (but you avoid generating temp files and the need to clean up). For complex text processing a Perl script will usually be simpler and faster.

Regarding /ERROR or dealing with errors in general. Don't forget there are "&&" (if success) and "||" (if error) separators. Unfortunately you need to explicitly return status, if your mainline needs to know the result.

Examples:

$ PIPE (SHOW JUNK && SHOW TIME || EXIT &$STATUS.OR.%X10000000)
$ SHOW SYM $STATUS
$STATUS == "%X10038060"

or

$ PIPE (SHOW JUNK || EXIT &$STATUS.OR.%X10000000 && SHOW TIME ; SHOW PROCESS ; SHOW SYSTEM)

[.OR. with STS$M_INHIB_MSG to prevent duplicate error message when exiting the pipe.]
A crucible of informative mistakes
Niall76
Frequent Advisor

Re: Can you do a F$EXTRACT on a PIPE output

Thanks all for your responses.