删除包含字符串后跟x个数字的行 [英] Remove lines containg string followed by x number of numbers

查看:114
本文介绍了删除包含字符串后跟x个数字的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想从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:

$ $ p $ grep -Ev'\ bvol([[:blank:]] + [[:数字:]] +){2}'文件

24545454,在冰上跳舞第5卷,454554,45454545
5454545,这个人是谁,545456454,4545454

模式([[:blank:]] + [[:digit:]] +){2在 vol 之后,至少会匹配两个以空格/制表符分隔的数字。


Hello I want to remove lines from a csv which contain the string vol followed by 2 or more number.

Examples data:

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

Desired Output:

24545454, Dancing on ice vol 5, 454554, 45454545
5454545, Who is the man, 545456454, 4545454

I know I can use:

cat $csv1 | grep -vi "vol" > $newcsv

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:

grep -Ev '\bvol([[:blank:]]+[[:digit:]]+){2}' file

24545454, Dancing on ice vol 5, 454554, 45454545
5454545, Who is the man, 545456454, 4545454

Pattern ([[:blank:]]+[[:digit:]]+){2} will match at least 2 numbers separated by space/tab after vol.

这篇关于删除包含字符串后跟x个数字的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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