Read CSV file with space delimiter

Highlighted
Five Stars

Read CSV file with space delimiter

Hello,

I have a csv file like this:

            11111111111            22222222222 33333333333333     xxxxxxxxxx

where the delimiter look like a single or multiple spaces.

In addition to that, the last column may contains spaces.

What is the best practice to read a similar file?

Thanks in advance.


Accepted Solutions
Eleven Stars

Re: Read CSV file with space delimiter

I am assuming that only last column can have space. 

 

 

"^\\s*(\\w+)\\s+(\\w+)\\s+(\\w+)\\s+(.*)"

Regards
Abhishek KUMAR

View solution in original post


All Replies
Eleven Stars

Re: Read CSV file with space delimiter

Does your schema is static or Dynamic ? Do you know many fields(Without space) your input can have ?

Regards
Abhishek KUMAR
Five Stars

Re: Read CSV file with space delimiter

Thanks Abhishek KUMAR for your reply.

The input file has always 4 columns, but the positions of the fields may change.i.e.:

11111111111 22222222222 333333333333 xxxxxxxxxxxxxx or

              11111111111 22222222222 333333333333 xxxx or 

  11111111111 22222222222 333333333333 xxxxxxxxxx or ....

Regards

Eleven Stars

Re: Read CSV file with space delimiter

try tFileInputregex

 

with regex expression 

"^\\s*(\\w+)\\s+(\\w+)\\s+(\\w+)\\s+(\\w+)\\s*"

Regards
Abhishek KUMAR
Five Stars

Re: Read CSV file with space delimiter

Thank you again.

At first glance, it's works.

But when the last column contains space, it split the value and get only the first part.

Can you update the regex expression to resolve this issue?

Regards

Eleven Stars

Re: Read CSV file with space delimiter

I am assuming that only last column can have space. 

 

 

"^\\s*(\\w+)\\s+(\\w+)\\s+(\\w+)\\s+(.*)"

Regards
Abhishek KUMAR

View solution in original post

Five Stars

Re: Read CSV file with space delimiter

Thanks a lot, its works fine now.

Regards

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 2

Part 2 of a series on Context Variables

Blog

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