× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Interestingly, Scott's message came to me only in Jim's response. Didn't
know about the datarea script or program. I'll have to check it out.
Sounds VERY cool!

As you can surmise, I am not in front of a terminal screen, so pls check my
spelling. Now to the point.

Mine also assumes that the foo= may occur anywhere within the line. If you
wanted to ensure that it occurred only at the beginning of the line, you'd
have to use (using Scott's as an example) :
New > sed -n ''s/^foo="\(....................\)"/\1/p''
Old > sed -n ''s/.*foo="\(....................\)".*/\1/p''

While it will work, Scott's original uses two redundant .* metastreams.
Since .* means "any number of any characters) it's unnecessary at the
beginning and end of the regular expression. The statement is the same with
and without these.

If you wanted to ensure that the string started with foo= and ended with the
terminating quote, it'd be more like:
s/^foo="\(.......................\)"$ where ^ anchors to the beginning
of the line, and $ anchors to the end.

But if you want to be sure that exactly 20 characters are within the quote,
I'd use the following for readability:
s/^foo="\(.\{20\}\)"/\1/p$
That looks for a line that begins with foo=" , contains 20 characters, then
another quote and end of line. Omit ^ and $ for middle-of-line.

Now, my solution would be:

qsh CMD('datarea -wl $(sed ''s/^foo="\(.\{20\}\)"/\1/p$'' < myfile)
MYDA.dataarea')

But Scott's is cool too since he doesn't hardcode the filename and data area
name. (At least not down in the code.)

Somewhere, buried in the stream file of arbitrary length, there may
or
may not be a string of the form
foo="<block of 20 characters>"

This is very similar to what Dennis Lovelady just posted... ack, I'm
too
slow... but mine does have some differences from his, so I'm posting
it
anyway:

PGM

CRTDTAARA DTAARA(TESTAREA) TYPE(*CHAR) LEN(20)
MONMSG CPF1023

ADDENVVAR ENVVAR(QIBM_QSH_CMD_ESCAPE_MSG) REPLACE(*YES) +
VALUE(Y)
ADDENVVAR ENVVAR(STMF) REPLACE(*YES) +
VALUE('/home/klemscot/testfile.txt')
ADDENVVAR ENVVAR(DTAARA) REPLACE(*YES) +
VALUE('TESTAREA')

QSH CMD('cat $STMF | +
sed -n ''s/.*foo="\(....................\)".*/\1/p'' |
+
datarea -wl $DTAARA.dtaara')

DSPDTAARA TESTAREA

ENDPGM

Differences between mine & Dennis:

a) Mine assumes the foo= can appear in the middle of other text.
(I'm
actually assuming you're trying to grab this out of an XML file)

b) Mine assumes data between quotes is always 20 chars, period.
Dennis
solution will take any length... (maybe I took you too literally)

c) Mine writes the output to a data area, his wrote it to an
environment
variable inside Qshell.

d) If there's more than one foo= string in the file, mine will only
take
the first one. Dennis' will take them all (but store them all
together
in one variable.)

So... mine is very similar, in some ways better, in some ways worse
than
Dennis'... but I thought it might be worth posting anyway.
--


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.