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

One Star

[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

Accepted Solutions
Highlighted
One Star

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

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.

All Replies
Four Stars

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

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
One Star

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

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.
Four Stars

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

Hi,
What is the error you are receiving?
Vaibhav
Highlighted
One Star

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

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.

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

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