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



It's not two % symbols, but a nice surprise was awaiting me when I did the
testing. It seems that after the "/$line" insertion the cursor (to use a
term I'm familiar with) is positioned at that point, such that a subsequent
search for "Description" finds the NEXT instance, not the first. So I can
make it work anyway, and I get the insertion of "/$end" at the right spot.

Patrik, thank you so much for your help. It seems that this is a very
arcane area of knowledge; I'm fortunate to have had your assistance to get
me across the finish line.

I also gleaned some useful tips from
https://www.grymoire.com/Unix/Sed.html though
it's not QSHELL or IBM i oriented.

For those seeking an answer to a similar problem, the full script is below,
with the comments that are actually in the script starting with #, and my
additional comments bracketed thus: /* comment */, i.e. CL-style. These
latter are not in the script. If you are reading this as an email the > at
the start of each line is not in the script, it just serves to indent it on
the MIDRANGE-L web page for readability

IFS stream file sedscript:
Note that my test spreadsheet has only two fields, "Item" and
"Description", but I've (hopefully) coded the below so it will work for any
number of columns. Where I've used "Description" in the script, you will
have to substitute the name of the last column on your spreadsheet.

# Insert the CGIDEV2 section name as first line
1i \ /* Insert as the first record */

/$start /* Insert this text */

# Increase the file size as required
s/RowCount="2"/RowCount="30000"/ /* The largest number of rows
expected, plus safety margin */
# Insert the CGIDEV2 section line START name for the row
/Description
/ { /* Anchor */
n /* Go down two
lines from the anchor, which is the last row heading */
n
i \
/$line /* Insert this
text */
}
# Insert the CGIDEV2 section line END name for the row
/Description/ { /* This is
"Description" text found AFTER the previous point of insertion */
n /* Go down two
lines after the last spreadsheet column ("Description in this case)*/
n
i > \
/$end /* Insert this
text */
}

Here is the command to test it in QSH:

cat my_template.xml | sed -f sedscript > sedout1.xml

Here is the relevant portion of CL to make it happen:

dcl &shellstr *char 1024 /* Qshell string to execute */
dcl &fromifs *char 128 '/usr/local/files/my_template.xml'
dcl &sedout *char 38 '/usr/local/files/sedout1.xml'

chgvar &shellstr ('cat ' *cat &fromifs *bcat ' | sed -f sedscript >' +
*bcat &sedout )
qsh cmd( &shellstr )

Note that in Paul Tuohy's article
<https://www.itjungle.com/2008/08/13/fhg081308-story01/>, he also
instructed that the data values be manually edited by bracketing them with
"/% %/", but you can put them like that directly in your spreadsheet
template line and they'll carry through fine. No need for manual editing
every revision to the spreadsheet.

Note: The method above worked for me. I can't guarantee it'll work on other
systems.

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.