× 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.



sed -n -e 's/oldstring/newstring/p' -e "s/'/''/g" < myfile

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-
bounces@xxxxxxxxxxxx] On Behalf Of Terrence Enger
Sent: Thursday, September 17, 2009 5:53 PM
To: Midrange Systems Technical Discussion
Subject: Re: Scanning a STMF for a string

Tïhank you, Scott. This is much cleaner than the code I was hacking
together toward the same end.

However, we seem to have reached the same point: ordinary characters
are okay, embedded blanks are okay, embedded double quotes are okay,
and
an embedded single quote makes the program fall over. Sigh.

I think the problem can be changed by an additional filter between sed
and datarea:
( read x ; echo "${x//'/''}" )
I say changed rather than fixed because datarea seems to count the
doubled single quote twice, provoking message "datarea: 001-2353 The
length of the data (21) is greater than the message length (20) of the
data queue." Sigh, sigh. If you truncate the string down to twenty
characters including the doubled single quote you end up with only the
leading nineteen characters in the data area. Sigh, sigh, sigh.

Can you come up with a simple solution for this one, Scott?

Cheers,
Terry.


On Thu, 2009-09-17 at 13:47 -0500, Scott Klement wrote:
hi James,

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.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



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.