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

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

[resolved] how to read data from text file from nth line to nth line?

hi ,
I have a input file like
aaa
bbb
ccc
ddd
eee
fff
ggg 
hhh
now i need to read  line from aaa to ddd only, without using the Header and Footer option,
That is. give condition like start line form if contains aaa  and end line from if contains ddd ..
please help me to sort out this
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

After your input file, put in a tJavaFlex component.
In the Main Code part of the tJavaFlex, you could do something like this:
OutputRow2.Field1 = "";
if(InputRow1.Field1.startsWith("aaa")||InputRow1.Field1.startsWith("bbb")||InputRow1.Field1.startsWith("ccc")||InputRow1.Field1.startsWith("ddd"))
{OutputRow2.Field1 = InputRow1.Field1;}
This would only make the output rows equal to the input rows when your input field started with any of these combinations.  Otherwise, the output row would be blank.  You can then use a tMap component to filter out any blank rows.

View solution in original post

4 Replies
Anonymous
Not applicable
Author

Hi,
- Read all the data
- Assign line number to each row using sequence generator
- Use tJavaRow to mark start row number and end row number using if-then-else condition and context variables for start and end
- Use tFilterRow component to filter required records.
- Use tMap to remove serial number and get required records in the output
I think this is what you need...
Vaibhav
Anonymous
Not applicable
Author

Hi sanvaibhav,
    Thanks for your Reply, As i am new to Talend.. i  dont know how to generate the sequence and the other steps.specially my text file is too complex.. . so can u please explain me step by step. or else whether are you having any other link  related to this issue?
Please help me to sort out this.
Anonymous
Not applicable
Author

Hi,
What is the error you are receiving?
Vaibhav
Anonymous
Not applicable
Author

After your input file, put in a tJavaFlex component.
In the Main Code part of the tJavaFlex, you could do something like this:
OutputRow2.Field1 = "";
if(InputRow1.Field1.startsWith("aaa")||InputRow1.Field1.startsWith("bbb")||InputRow1.Field1.startsWith("ccc")||InputRow1.Field1.startsWith("ddd"))
{OutputRow2.Field1 = InputRow1.Field1;}
This would only make the output rows equal to the input rows when your input field started with any of these combinations.  Otherwise, the output row would be blank.  You can then use a tMap component to filter out any blank rows.