Four Stars

extract data from text file

I have a regular text file. I need to extract the block between "report data" and "end of report data": 
text lines
more and more lines
............
report data
text line needed 1
text line needed 2
text line needed n
end of report data
............
more and more lines
What's the best way to approach this? An example would be really appreciated. Thank!
4 REPLIES
Seventeen Stars

Re: extract data from text file

Not that trivial. I suggest you read the lines line by line and aggregate them in a tJavaRow with a StringBuilder and check the lines for your marker lines. You will hardly find one building an example for that. This is a typical use case where we use plain java programming.

Re: extract data from text file

This one is not as difficult as you may think. Here's a simplified example of one approach:

Job Overview:


code in tJavaRow_1 (note the default for context.read_data should be false

if( input_row.line.matches("report data") ) {
context.read_data = true;
}
if( input_row.line.matches("end report data") ) {
context.read_data = false;
}
output_row.line = input_row.line;

Tmap:


Results:

Test file:

Re: extract data from text file

oops, looks like the screenshots got a little confused.
Results:


Test File:

Four Stars

Re: extract data from text file

John - this is perfect! thank you!