Page 1 of 1

Input file line number (N-1) and (N+3) copy

PostPosted: Thu Sep 27, 2012 11:49 am
by ankushgattani
Hi,

i am trying to build a REXX, which does the following:
Find for 'XYZ' in the input file. lets say it was found in Nth line.
Then I've to copy (N-1)th and (N+3)th line to my output file.
I've to perform the copy operation for each occurence of 'XYZ' in the input file.
'XYZ' will always occur at 70th cloumn, if it occurs.

I am trying to read the input file line by line.
but not sure how to go about (N-1) and (N+3) lines.

Re: Input file line number (N-1) and (N+3) copy

PostPosted: Thu Sep 27, 2012 4:50 pm
by NicC
before reading your next line save your last line that way you have n-1 in a save area. then read 3 more lines and you are at n+3. Write save area and current line. Simple?

Re: Input file line number (N-1) and (N+3) copy

PostPosted: Fri Sep 28, 2012 10:43 am
by expat
Stem variables would appear to be the quickest and easiest solution

Re: Input file line number (N-1) and (N+3) copy

PostPosted: Fri Sep 28, 2012 11:46 am
by NicC
Unless you have loadsa input - but define 'loadsa'

Re: Input file line number (N-1) and (N+3) copy

PostPosted: Fri Sep 28, 2012 3:52 pm
by ankushgattani
My input file has some 100s of records only.

Re: Input file line number (N-1) and (N+3) copy

PostPosted: Sat Sep 29, 2012 12:31 am
by NicC
In that case one execution of EXECIO to read all the data into a stem then you can refer to stemname.n, stemname.n-1 and stemname.n+2. OK best to use proper variable names for n-1 and n+2 - n_minus_one and n_plus_2 would be fine. n_minus_one = n - 1 etc