how to get file name dyanamically

Highlighted
Five Stars

how to get file name dyanamically

Hi, Below are some of file names:
1)ut_full_load_rta_fast_1_23_20182312_1523.log
2)ut_fullload_first_extract_1_20183101_2356.log
3)ut_catload_dyanamic_overload_fan_2_20182107_1245.log
and so on

My required output in excel to get Table Names from above file names as below respectively:
1)rta_fast
2)first_extract
3)dyanamic_overload_fan

Can anyone help on this?


Accepted Solutions
Seven Stars

Re: how to get file name dyanamically

replaceAll("ut_.*load_", "").replaceAll("_\\d{0,}_.*","");

 

try this


All Replies
Fifteen Stars TRF
Fifteen Stars

Re: how to get file name dyanamically

I suppose you are using a tFileList, so the filename is associated to the variable tFileList_1_CURRENT_FILE. Using a regex you can get what you want for example into an other global variable:
globalMap.put("TableName", ((String) globalMap.get(tFileList_1_CURRENT_FILE).replaceAll("^ut_.*load_", "")).replaceAll ("_[0-9]_.*$", ""))
It's possible there is a syntax error, sorry I can try just now.
Hope this helps.

TRF
Five Stars

Re: how to get file name dyanamically

Hi,

Thanks for Reply

I am getting perfect output but there are some other files which look like:

ut_load_fast_read_20181212_1524

 

Required Table Name : fast_read

Seven Stars

Re: how to get file name dyanamically

replaceAll("ut_.*load_", "").replaceAll("_\\d{0,}_.*","");

 

try this

Five Stars

Re: how to get file name dyanamically

Hi,

Thanks for reply.

This Solution worked.

Can you please explain what does replaceAll("_\\d{0,}_.*","")  mean

 

Thanks,

Raj

Seven Stars

Re: how to get file name dyanamically

it replaces all substrings of type <_><any number of digits><_><anything after that> with <""> i.e. empty string.

 

 

 

regards

chandra kant 

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Download