使用Grep搜索CSV文件 [英] Searching a CSV File Using Grep

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

问题描述

让我们说我有一个csv文件,如下所示:

Lets say I have a csv file like this:

a,b1,12,
a,b1,42,
d,e1,12,
r,12,33,

我想使用grep仅返回第三列= 12的行.因此它将返回:

I want to use grep to return only only the rows where the third column = 12. So it would return:

a,b1,12,
d,e1,12,

但不是:

r,12,33,

对正则表达式有什么想法可以使我做到这一点?

Any ideas for a regular expression that will allow me to do this?

推荐答案

我会直接跳到awk来准确测试值

I'd jump straight to awk to test the value exactly

awk -F, '$3 == 12' file.csv

此方法以及任何基于正则表达式的解决方案都假定前两个字段的值不包含逗号

This, and any regexp-based solution, assumes that the values of the first two fields do not contain commas

这篇关于使用Grep搜索CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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