如何仅从 CSV 文件中提取和路由指定的列并删除所有其他列 [英] How to extract and route only specified columns from a CSV files and drop all other columns

查看:25
本文介绍了如何仅从 CSV 文件中提取和路由指定的列并删除所有其他列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 CSV 文件中提取几个字段及其值,并删除/删除文件中的所有其他字段.请帮忙.我想我们可以使用 RoutText 处理器.请告诉我如何为路由指定字段编写正则表达式并删除其他所有内容.谢谢

I want to extract few fields along with its value from a CSV file and drop/delete all other fields in the file. Please help. I think we can use RoutText processor.Please tell me how to write the regular expression for the routing only specified fields and dropping everything else. Thanks

示例-从附加的快照中,我只想沿着机智命中值(每条记录/行)路由名字、姓氏和兄弟姐妹"字段.删除剩余的列,如State、Age、Apt no、Country、Gender".

Example- from he snapshot attached I only want to route 'Firstname,Lastname and Siblings' fields along wit hits value(each record/row). Delete the remaining columns like 'State, Age, Apt no,Country,Gender'.

请告诉我什么是正确的处理器,以及使用什么配置属性来实现这一点.谢谢

Please tell me what is the correct processor for this and what configuration properties to use in order to achieve this. Thanks

附上快照以供参考.

推荐答案

您可以为此使用 ConvertRecord.向 CSVReader 提供完整架构,并仅向 CSVRecordSetWriter 提供包含您想要的字段的架构.如果您不知道输入模式(但您知道它至少包括您要发送的字段),您可以让阅读器使用标题中的字符串字段,这将创建一个输入模式(使用标题行)和假设所有字段都是字符串.但是,输出模式将包含选定字段及其类型,ConvertRecord 将处理其他字段的删除",以及每个选定字段从 String 到所需数据类型的任何转换.

You can use ConvertRecord for this. Provide the full schema to the CSVReader, and provide the schema with only the fields you want to the CSVRecordSetWriter. If you don't know the input schema (but you know it includes at least the fields you want to send along), you can have the reader Use String Fields From Header, that will create an input schema (using the header line) and assume all fields are strings. However the output schema would have the selected fields along with their types, and ConvertRecord will handle the "deletion" of the other fields, as well as any conversion from String to the desired data type for each of the selected fields.

这篇关于如何仅从 CSV 文件中提取和路由指定的列并删除所有其他列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆