简体   繁体   中英

How to extract key values from CSV in Talend

I have csv data file as below:

 `Column1`                  `Column2`                    `Column3`           
    
{'name':'Steve Jobs'}   ,    {'first_name':'Steve'}  , {'last_name':'Jobs'} 
    
{'name':'Mark Zuckerberg'} ,  {'first_name':'Mark'}  ,  {'last_name':'Zuckerberg'}

{'name':'Steve Jobs'}   ,    {'first_name':'Steve'}  , {'last_name':'Jobs'} 

I want my data as below using Talend Tool:

`name`          `first_name`    `last_name`

Steve Jobs       Steve          Jobs

Mark Zuckerberg  Mark          Zuckerberg

Steve Jobs       Steve         Jobs

You can use substring() and indexOf() functions to achieve this.

Explanation:

  1. Since Key and Value is separated by : we can substring after the : and before }
  2. To get the position of then : and } , we can use indexOf function

Below is the condition used in tMap for three columns,

row1.Column1.substring(row1.Column1.indexOf(":")+2, row1.Column1.indexOf("}")-1) 
row1.Column2.substring(row1.Column2.indexOf(":")+2, row1.Column2.indexOf("}")-1) 
row1.Column3.substring(row1.Column3.indexOf(":")+2, row1.Column3.indexOf("}")-1) 

Result,

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM