|
Vern,Good point - personally I'm using CGIDEV2 to generate some XML, and there is a value at the head of it that is not know until the whole thing is created - number of rows, say - so I have a very specific, unique marker for that value, and I always know which line it's on - so I use this technique there.
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.)
This is trickier - in our case, I don't think this will happen, at least not yet. I believe PASE handles these things (CCSIDs) differently, so that might be an option to look at, if one wants to continue with this technique.
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!
As an Amazon Associate we earn from qualifying purchases.
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.