双引号内分离逃逸 [英] Escaping separator within double quotes

查看:121
本文介绍了双引号内分离逃逸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用awk与解析我的数据,作为分隔符的输入是一个CSV文件。但是,也有,该分离由双引号()。

I am using awk to parse my data with "," as separator as the input is a csv file. However, there are "," within the data which separated by double quote (" ").

示例

filed1,filed2,field3,"field4,FOO,BAR",field5

如何忽略逗号,双引号内的,这样我可以用awk正确解析输出?我知道我们可以在Excel中做到这一点,但是我们如何做到在AWK?

How can i ignore the comma "," within the the double quote so that I can parse the output correctly using awk? I know we can do this in excel, but how do we do it in awk?

推荐答案

对于一个非常COM prehensive说明看这里:

For a very comprehensive description look here:

<一个href=\"http://web.archive.org/web/20120531065332/http://backreference.org/2010/04/17/csv-parsing-with-awk/\"相对=nofollow> http://backreference.org/2010/04/17/csv-parsing-with-awk/ (archive.org版)

http://backreference.org/2010/04/17/csv-parsing-with-awk/ (archive.org version)

不过,这不是分析,而是用正则表达式作弊。对于任何事情比你应该使用Perl / Python的一个解析器库,如CSV的Python页面上的例子更复杂。

But this is not parsing, but cheating with regexp. For anything more complicated than the examples on the page you should use Perl/Python with a parser library like "csv" for Python.

这篇关于双引号内分离逃逸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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