From Thursday, July, 9, 3:00 PM Pacific,
our Community site will be in
read-only mode
through Sunday, July 12th.
Thank you for your patience.

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

Highlighted
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.

View solution in original post


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
Highlighted
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.
Highlighted
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.

View solution in original post

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog