问题
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