Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

Field Seperator - Multiple Spaces

Highlighted
One Star
One Star

Field Seperator - Multiple Spaces

Hi,

I have a record that has spaces as seperators, but unfortunately not just one space each time, any number of spaces.

Example

1 2 3 4 5 6 7

Using " " as seperator does not work, so I either need a better seperator or to strip out any unrequired spaces before delimiting, the trouble here is that I still need a single space in order to delimit to stripping all spaces is no good.

Regards,
Highlighted
Five Stars

Re: Field Seperator - Multiple Spaces

Hi,
You can use just one space as a separator and check trim all columns in your tFileInputDelimited advanced settings.
Regards,
Youssef
Highlighted
One Star
One Star

Re: Field Seperator - Multiple Spaces

Youssef,

Thanks for the response. The number of spaces is random, so this will not quite work. I did think of doing several tmap with a StringHandling.EREPLACE(row1.newColumn," "," ") for each number of spaces, but doing this 6/7 times would not be ideal.

Example

1 2 3 4 5
1 2 3 4 5


Cheers,

John.
Highlighted
Five Stars

Re: Field Seperator - Multiple Spaces

The number of spaces is random

Yes, but at least you have one space. so define just one space as a separator and trim your columns to remove useless spaces.
Regards,
Youssef
Highlighted
One Star
One Star

Re: Field Seperator - Multiple Spaces

Youssef,

If I use one space as a seperator I end with a new column every time I hit a space

so

1 2 3

becomes

1|2||3

and not

1|2| 3


I'll try to strip out the additional spaces before I delimit.


John.
Highlighted
Five Stars

Re: Field Seperator - Multiple Spaces

Sorry, I didn't realize your problem.
You can use tFileInputRegex to retrieve your columns , in your case the regular expression would be like this: "(+)"+"+"+"(+)"
Here, I suppose that you have 2 columns.
Regards,
Youssef
Highlighted
Employee

Re: Field Seperator - Multiple Spaces

In case Perl users are reading this topic, here comes a difference between Java and Perl. In Perl tFileInputDelimited, you can set the "Field Separator" to :
/ +/

(no quote)
Highlighted
One Star
One Star

Re: Field Seperator - Multiple Spaces

Thanks for your help guys,

In the end I decided to read the file as a one line column delimited by '\n', then using treplace I have set conditions to remove the various number of blank spaces possible and replace with a single space, then an extractdelimited using a single space as the delimiter.

Its now working.

As a product trial I am reworking a series of Ab Initio Graphs, so am probably going to post a few questions.

Thanks again.
Highlighted
One Star

Re: Field Seperator - Multiple Spaces

Hi,
I have set conditions to remove the various number of blank spaces possible and replace with a single space

sounds complex. You can use (in java) the following code to change your spaces:
stringColumn.replaceAll(" +", " ");

The second parameter could be whatever you want (or need).
Bye
Volker
One Star
One Star

Re: Field Seperator - Multiple Spaces

Thanks Volker, I'll give it a go

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