how to get file name dyanamically

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 

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

Downloads and Trials

Test drive Talend's enterprise products.

Downloads