如何提取CSV文件的一列 [英] How to extract one column of a csv file

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

问题描述

如果我有一个csv文件,是否有一种快速的bash方法可以只打印出任何一列的内容?可以安全地假设每一行具有相同的列数,但是每一列的内容将具有不同的长度.

If I have a csv file, is there a quick bash way to print out the contents of only any single column? It is safe to assume that each row has the same number of columns, but each column's content would have different length.

推荐答案

您可以为此使用awk.将"$ 2"更改为所需的第n列.

You could use awk for this. Change '$2' to the nth column you want.

awk -F "\"*,\"*" '{print $2}' textfile.csv

这篇关于如何提取CSV文件的一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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