您好,我想从csv中删除包含字符串vol
和2个或更多数字的行。
示例数据:
2454564, Stage Mechanics vol 4 8 9, 121545, 454545454
24545454, Dancing on ice vol 5, 454554, 45454545
5454545, Who is the man, 545456454, 4545454
8785648654, year of the Panda vol 89 12, 545454, 545454
期望输出:
24545454, Dancing on ice vol 5, 454554, 45454545
5454545, Who is the man, 545456454, 4545454
我知道我可以用:
cat $csv1 | grep -vi "vol" > $newcsv
但很明显,这只会删除“vol”中的行-我该如何将后跟2个或更多数字规则合并到此代码中?
谢谢
最佳答案
你可以使用这个grep:
grep -Ev '\bvol([[:blank:]]+[[:digit:]]+){2}' file
24545454, Dancing on ice vol 5, 454554, 45454545
5454545, Who is the man, 545456454, 4545454
模式
([[:blank:]]+[[:digit:]]+){2}
将匹配vol
之后由空格/制表符分隔的至少两个数字。关于linux - 删除包含字符串和x个数字的行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38105511/