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



What Michael actually needs is an OO language that is capable of handling
and manipulating hierarchical data structures as XML and JSON.


On Tue, Sep 2, 2014 at 6:44 PM, Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
wrote:

Vern,

This can be a good solution if the circumstances are right. However, I
think it's worth noting two things:

1) sed has no knowledge of XML syntax. So you need to be careful that
what you find/replace doesn't break the XML document... (Just as Henrik
pointed out.)

2) This method will translate all data into EBCDIC when reading the file,
and translate back to UTF-8 when writing the file back out. If you have
any UTF-8 characters that don't exist in your job's EBCDIC CCSID, then the
results will not be satisfactory.

If neither of these are a problem in your particular instance, however,
this can be a good solution.

-SK



On 9/2/2014 11:28 AM, Vernon Hamberg wrote:

Michael

You should look at using the sed function in QShell - it has a
substitute option that lets you do exactly what you want. Making the
change in place requires a couple dance steps, but it's not too hard -
see example below.

It can be set to replace only the first instance, or all instances of
the search string - so you may need something unique to search for -
depends on what you need to do.

It CAN also be set to look only within a range or lines (delimited by
CRLF or the like).

Here is an example using the qsh command -

qsh cmd('export QIBM_CCSID=1208 && sed
"firstlinetosearh,lastlinetosearch s/searchstring/replacestring/g"
ifsfilepath > temp.tmp && mv temp.tmp ifsfilepath')

I am writing to an XML file, so I set the CCSID for QShell to UTC-8 -
that is because the redirect in QShell uses the job CCSID, which would
be 37, of course, usually.

The double ampersands are command separators - if a command fails, the
whole thing stops - so if the export fails, the sed and mv are not
executed - if sed fails, mv is not executed.

The lines to search are optional, if you want to search the entire IFS
file, but they help if you know the range where the value-to-replace is
located. There are some other ways to delimit the search range, I believe.

The "g" right after "replacestring/" means greedy, IIRC - it makes sed
replace every instance of the search string.

The > redirects output to another IFS file. You can't redirect to the
one you are reading from.

Finally, the mv command (move) takes temp.tmp and overwrites it to the
IFS file.

I'm using it now - works very well.

There IS an option in other version of sed that let you do an in-place -
maybe the version in PASE can do that - then you would have different
CCSID questions, etc.

HTH
Vern

On 9/2/2014 10:02 AM, Michael Ryan wrote:

I need to update data in a stream file located in ths IFS (or on a QNTC
share). I know I can read the data from the file, and then write to
another
file, and then delete/rename I guess, but I want to update in place. I
don't want to use any procedures that add a CRLF. I'm thinking of using
read() and write(), but I'm not sure how to handle the update. Probably
pretty simple. Thanks!


--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.





As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.