Remove lines containg string followed by x number of numbers

主宰稳场 提交于 2020-01-15 11:06:07

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/38105511/remove-lines-containg-string-followed-by-x-number-of-numbers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!