删除包含字符串后跟x个数字的行 [英] Remove lines containg string followed by x number of numbers
问题描述
你好,我想从csv中删除包含字符串 vol
后跟2或更多数字的行。
示例数据:
2454564,Stage Mechanics vol 4 8 9 ,121545,454545454
24545454,Dancing on ice vol 5,454554,45454545
5454545,这个男人是谁,545456454,4545454
8785648654,熊猫卷89 12年,545454年,545454年
所需输出:
24545454,Dancing on ice vol 5,454554,45454545
5454545,这位男士是谁,545456454,4545454
我知道我可以使用:
cat $ csv1 | grep -vivol> $ newcsv
但是显然这只会删除带有vol的行 - 如何合并后面的由2个或更多的数字规则来代码?
谢谢 >你可以使用这个grep: 模式 Hello I want to remove lines from a csv which contain the string Examples data: Desired Output: I know I can use: but obviously this would just remove lines with "vol" in- how do I incorporate the followed by 2 or more numbers rule to this code? Thanks You can use this grep: Pattern 这篇关于删除包含字符串后跟x个数字的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ $ p $ grep -Ev'\ bvol([[:blank:]] + [[:数字:]] +){2}'文件
24545454,在冰上跳舞第5卷,454554,45454545
5454545,这个人是谁,545456454,4545454
([[:blank:]] + [[:digit:]] +){2在
至少会匹配两个以空格/制表符分隔的数字。 vol
之后,vol
followed by 2 or more number. 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
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}
will match at least 2 numbers separated by space/tab after vol
.