gpt4 book ai didi

regex - sed、awk 或 perl 过滤不完整的数据列

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:28:09 26 4
gpt4 key购买 nike

自然语言处理新手。我有包含大约一百万行的 csv 文件。我想过滤掉不包含任何数据的第三行。例如

user1,user2, it really is  
user3,user4, oh nothin
user5,user9,
user7,user8,
user9,user10,
user11,user12, i know im in
user13,user14,
user15,user16,
user17,user18, i think that might
user19,user20, what u
user21,user22, hmmm you never know
user23,user24, nicee

预期输出

user1,user2, it really is 
user3,user4, oh nothin
user11,user12, i know im in
user17,user18, i think that might
user19,user20, what u
user21,user22, hmmm you never know
user23,user24, nicee

我试过了

awk -F',+' 'NF == 3' file > file    

然而,不起作用

最佳答案

在 Perl 中,这将打印一行,除非它以逗号和空格结尾。

perl -ne'/,\s*$/ or print' file

输出

user1,user2, it really is
user3,user4, oh nothin
user11,user12, i know im in
user17,user18, i think that might
user19,user20, what u
user21,user22, hmmm you never know
user23,user24, nicee

关于regex - sed、awk 或 perl 过滤不完整的数据列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29459003/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com