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

查看:107
本文介绍了如何从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

示例-从附带的快照中,我只想沿机智命中值(每个记录/行)路由名字,姓氏和兄弟姐妹"字段.删除其余的列,例如州,年龄,住所编号,国家/地区,性别".

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天全站免登陆