如何在Bash脚本中解析CSV? [英] How to parse a CSV in a Bash script?

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

问题描述

我正在尝试分析可能包含100k +行的CSV.这是我的标准:

I am trying to parse a CSV containing potentially 100k+ lines. Here is the criteria I have:

  1. 标识符的索引
  2. 标识符值

我想检索CSV中在给定索引中具有给定值(用逗号分隔)的所有行.

I would like to retrieve all lines in the CSV that have the given value in the given index (delimited by commas).

有什么想法,需要特别考虑表现吗?

Any ideas, taking in special consideration for performance?

推荐答案

使用普通的旧 grep cut 的第一个原型:

First prototype using plain old grep and cut:

grep "${VALUE}" inputfile.csv | cut -d, -f"${INDEX}"

如果速度足够快并提供适当的输出,就可以了.

If that's fast enough and gives the proper output, you're done.

这篇关于如何在Bash脚本中解析CSV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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