extract data from text file

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!
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!

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch