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



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!


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.