csv 删除第二列少于 X 个单词的行[已关闭]

问题描述 投票:0回答:1

我有一个大的 csv (35gb),格式如下:

id, text, other_info
1, "this is some text, a news report citing more than 30 sources, including investors", "info"
11, "this is some text", "info"

问题是

text
有时少于10个单词,我想删除这些行。 请问有什么快速的方法吗?

bash awk sed
1个回答
0
投票

基于此示例文件,test.csv:

1,a,other_info
2,a b,other_info
3,a b a b ab ab ab ab ab ab ab ab ab ab ab ab ab,other_info
4,a c,other_info
5,a b a b ab ab ab ab ab ab ab ab ab ab ab ab ab,other_info
6,a b a b ab ab ab ab ab ab ab ab ab ab ab ab ab,other_info

运行

awk -F ',' '{split($2,words," "); if (length(words) >= 10) print}' test.csv
产量:

3,a b a b ab ab ab ab ab ab ab ab ab ab ab ab ab,other_info
5,a b a b ab ab ab ab ab ab ab ab ab ab ab ab ab,other_info
6,a b a b ab ab ab ab ab ab ab ab ab ab ab ab ab,other_info
© www.soinside.com 2019 - 2024. All rights reserved.