Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - notMatch

I want to select from a file all the lines which do not match a specific pattern; I know I have to use -notMatch option of select-string but I just can't figure it out how. (I'm looking for something like GREP's -v function) Any example would be useful. Thanks in advance.

like image 385
55651909-089b-4e04-9408-47c5bf Avatar asked Apr 23 '12 17:04

55651909-089b-4e04-9408-47c5bf


2 Answers

Can't you use the following

-notmatch "(?<!(void|double|char|int)\s+|//.*)\b$f\b"
like image 91
ondrovic Avatar answered Nov 14 '22 19:11

ondrovic


I think you still want to match rather than notmatch. To exclude the function return type or comments, you need a 'negative look behind asserion'. Perhaps this will do what you require?

$f = 'my_function'
select-string test.txt -Pattern "(?<!(void|double|char|int)\s+|//.*)\b$f\b"

The (?<!...) part says don't match if '...' is found at this point in the source text.

like image 41
Damian Powell Avatar answered Nov 14 '22 19:11

Damian Powell