Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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!
Labels (2)
4 Replies
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

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

Job Overview:

0683p000009ME93.png
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:

0683p000009ME4d.png
Results:
0683p000009ME98.png
Test file:
Anonymous
Not applicable
Author

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

0683p000009MDs6.png
Test File:

0683p000009MDlC.png
Anonymous
Not applicable
Author

John - this is perfect! thank you!