Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regina working with a file an manipulating its data

Status
Not open for further replies.

Xizor76

Technical User
Jul 9, 2008
5
DE
Hi,

I'm very new to Rexx and I have the following task to do.

A file is put via ftp on my windows server. This file contains data which causes errors on further processing. I would like to remove that data from the file an store it in another. The data begins with a certain pattern like eg. AB1FGZ. How could I do this?

Thanks for your help!

Regards,
Xi
 
You can read the input file line by line. In each line search for the patterns and if found then write the line to the output file.
Here is an example for an input file named 'myinput.txt'
Code:
line1
Pattern1 .. line2
line3
pattern2 .. line4
line5
other data
...
and here the program which process the input file and writes the desired lines to the output file 'myoutput.txt':
Code:
/***************************/
/*      Main program       */
/***************************/
input_file  = 'myinput.txt'
output_file = 'myoutput.txt'

/* Open output for writing */
call lineout output_file, , 1
/* Read lines in loop and process them */
do while lines(input_file) \= 0
  line = strip(linein(input_file))
  if find_patterns(line) = 1 then do
    /* write line to the output file */
    call lineout output_file, line
  end
end
/* close all files */
call lineout output_file
call lineout input_file
/*-------------------------*/
exit

/***************************/
/*  Functions/Procedures   */
/***************************/
find_patterns: procedure
/* 
  argument: line
  returns 1 if pattern found
     else 0
*/
parse upper arg line
retval = 0
if pos('PATTERN1', line) > 0  |,
   pos('PATTERN2', line) > 0 then do
   retval = 1
end
return retval
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top