Linux工具解析CSV文件 [英] Linux Tool To Parse CSV files

查看:1012
本文介绍了Linux工具解析CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道可以用于解析CSV文件的独立命令行程序吗?

Is anyone aware of a standalone command line program that can be used to parse CSV files?

要执行以下操作:

csvparse -c 2,5,6 filename

从所有行的第2 5和6列中提取字段。

to extract fields from columns 2 5 and 6 from all rows.

应该能够处理csv文件格式: http://tools.ietf.org/html/rfc4180 ,这意味着适当地引用字段和转义内部引号,因此对于包含3个字段的示例行:

It should be able to handle the csv file format: http://tools.ietf.org/html/rfc4180 which means quoting fields and escaping inner quotes as appropriate, so for an example row with 3 fields:


field1,field,number2有
引号和逗号,field3

field1,"field, number ""2"", has inner quotes and a comma",field3

,因此如果我请求上面一行的字段2,那么:

so that if I request field 2 for the row above I get:


字段,数字2,具有内部引号
和逗号

field, number "2", has inner quotes and a comma



我感谢有很多解决方案,perl ,awk(etc ..)这个问题,但我想一个本机bash命令行工具,不要求我调用一些其他脚本环境或写任何额外的代码(!)。

I appreciate that there are numerous solutions, perl, awk (etc..) to this problem but I would like a native bash command line tool that does not require me to invoke some other scripting environment or write any additional code (!).

推荐答案

我的FOSS CSV流编辑器 CSVfix 做你想要的。有一个用于Windows的二进制安装程序和一个用于UNIX / Linux的可编译版本(通过makefile)。

My FOSS CSV stream editor CSVfix does exactly what you want. There is a binary installer for Windows, and a compilable version (via a makefile) for UNIX/Linux.

这篇关于Linux工具解析CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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