如何削减csv的列 [英] how to cut columns of csv

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

问题描述

我有一组csv文件(大约250个),每个文件具有300到500条记录.我需要从每个文件中删除2或3列,并将其存储到另一个文件中.我正在使用 ubuntu操作系统.有什么方法可以在命令或实用程序中完成此操作吗?

I have a set of csv files (around 250), each having 300 to 500 records. I need to cut 2 or 3 columns from each file and store it to another one. I'm using ubuntu OS. Is there any way to do it in command or utility?

推荐答案

如果您知道字段内部未出现列定界符,则可以使用cut.

If you know that the column delimiter does not occur inside the fields, you can use cut.

$ cat in.csv
foo,bar,baz
qux,quux,quuux
$ cut -d, -f2,3 < in.csv 
bar,baz
quux,quuux

您可以使用shell内置的"for"循环遍历所有输入文件.

You can use the shell buildin 'for' to loop over all input files.

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

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