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



Yes, that's exactly it. Just the first time. I'm playing around with the d
function in sed, but not seeming to make it work.


On Tue, Sep 2, 2014 at 3:20 PM, Vernon Hamberg <vhamberg@xxxxxxxxxxxxxxx>
wrote:

Are you saying you want to replace

<tag>any kind of stuff</tag>

with

<tag></tag>

the first time it appears in the file?

Or every time?


On 9/2/2014 1:29 PM, Michael Ryan wrote:

Really what I want to do is find the first match for <tag>, delete that
line, and insert <tag></tag>. Free adult beverage (next time we meet) to
the sed expert that comes up with it first.


On Tue, Sep 2, 2014 at 2:11 PM, Michael Ryan <michaelrtr@xxxxxxxxx>
wrote:

Is there a way in sed to match any character? I'd like to match
<tag>xxx</tag> where xxx could be any three characters. Bonus points if I
could skip <tag></tag>! :) Thanks!


On Tue, Sep 2, 2014 at 1:53 PM, Michael Ryan <michaelrtr@xxxxxxxxx>
wrote:

Thanks Charles. Indeed, this XML is created by an internal process and
the structure is known. I actually use Scott's eXpat processor to get
the
data from the XML document, and that's been in place for years. This is
a
'special' thing to modify existing data stores of XML documents.


On Tue, Sep 2, 2014 at 1:42 PM, Charles Wilt <charles.wilt@xxxxxxxxx>
wrote:

In addition to Scott's points..

Trying to process XML with text functions is pretty much doomed to fail
unless you're dealing with a limited known set of XML docs.

A nice thread on the subject...

https://stackoverflow.com/questions/1732348/regex-match-
open-tags-except-xhtml-self-contained-tags/1732454#1732454
also see this article (referenced in the thread and vice versa)
http://blog.codinghorror.com/parsing-html-the-cthulhu-way/

The OP mentions he "has lots of documents", so I'd bet that he doesn't
"know" them all that well; unless they happen to have been all
generated
by
his own processes. :)

The OP has an XML document and wants to process it in, make certain
changes
and output it as XML. This is also known as an XML transformation;
specifically an XML to XML transformation.

And there exists languages to do just that..
https://en.wikipedia.org/wiki/XML_transformation_language

Charles



On Tue, Sep 2, 2014 at 12: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.


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



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