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



I have to do this with an XML file - I use sed to do a replace-in-place - got the basic idea somewhere on the net.

sed in QShell and probably in PASE do not have an option for the output to be the same file as the input - but this does that. It is a routine that receives various values to adjust the sed command. This one uses the QShell version of sed - that's why I have the CCSID setting in there.

P replaceInPlace B
D replaceInPlace PI
D pFile 256A VARYING
D CONST
D pLineFrom 10I 0 CONST
D pLineTo 10I 0 CONST
D pSearchFor 64A VARYING
D CONST
D pReplaceWith 64A VARYING
D CONST
D pReplaceAll N CONST

// Command string for running sed function
d sedCmd s 1024a varying

// Your calculation code goes here

sedCmd = 'QSH CMD(+
''export QIBM_CCSID=1208 +
&& sed "' + %char(pLineFrom) + ',' +
%char(pLineTo) +
' s/' + pSearchFor +
'/' + pReplaceWith + '/';

if pReplaceAll;
sedCmd += 'g';
endif;

sedCmd += '" ' + pFile + ' > /tmp/temp' + jobNbr + '.tmp +
&& mv /tmp/temp' + jobNbr + '.tmp ' + pFile + ''')';
qcmdexc(sedCmd : %len(sedCmd));

RETURN;
P replaceInPlace E

HTH
Vern

On 6/20/2016 4:15 PM, Buck Calabro wrote:
On 6/20/2016 4:37 PM, Darryl Freinkel (gmail) wrote:

I have a procedure that retrieves a file off a UNIX server onto the IFS.
I need to strip off the first character of the record if it is an 'S'.
*The* record? As in there is only one leading 'S' in the file?
Or *The first S of every record*?
Understanding that a Unix / stream file doesn't really have a concept of
'record' as we recognise it.

Is there an easy way to do this without having to import the file, strip the
character and then writing it back to the IFS?
I have sed and grep in both my PASE and QShell environments. It's been
so long that I'm not sure where I got them from. If I were starting out
now I'd probably hit up the YiPS:
http://yips.idevcloud.com/wiki/index.php/PASE/OpenSourceBinaries Check
out their chroot.

sed is only one way. Anything that can read stdin, run a regex and
write to stdout would work just as easily. Perl, PHP, and Python all
come to mind.

A completely untested regex off the top of my head:
find ^S(.*)
replace \1
With sed, that might look like sed -E "s/^S(.*)/\1/" < input > output



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.