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

查看:30
本文介绍了如何在 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?

推荐答案

第一个使用普通 grepcut 的原型:

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