I am struggeling to combine -notmatch expressions using powershell, just like what I do under Linux e.g. with grep -v "/aaa/" | grep -v "/bbb/". In other words I have the input in.txt looking as follows:
/aaa
/aaa/x.txt
/bbb
/bbb/y.txt
/ccc
/ccc/z.txtI want to end up with an file out.txt
/aaa
/bbb
/ccc
/ccc/z.txtWhat I have so far is cat in.txt | ?{$_ -notmatch '/aaa/'} > out.txt;, but how do I generalize this?
PS: Yes, I searched the web for examples or manpage, but I guess I am stuck in my bubble.
References
1 Answer
Pipe a second -notmatch:
cat in.txt | ?{$_ -notmatch '/aaa/'} | ?{$_ -notmatch '/bbb/'} > out.txt;Or to shorten it:
cat in.txt | ?{$_ -notmatch '/aaa/|/bbb/'} > out.txt;It should produce your expected result.
2