Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove lines which start with *(asterik) in powershell select-string output

I am working on a code so that it find lines which has $control but should remove lines which start with * at first column

I am working with following but doesn't seem to work ..

  $result = Get-Content $file.fullName | Select-String $control | Select-String -pattern "\^*" -notmatch

Thanks in advance

like image 273
Powershel Avatar asked Mar 24 '23 15:03

Powershel


1 Answers

You're escaping the wrong character. You do not want to escape ^ as that's your anchor for "starting with". You'll want to escape the asterix, so try this:

$result = Get-Content $file.fullName | Select-String $control | select-string -pattern "^\*" -notmatch

Also, if all you want is the lines, you could also use this:

Get-Content $file.fullName | ? { $_ -match $control -and $_ -notmatch '^\*'}
like image 53
Frode F. Avatar answered Apr 10 '23 20:04

Frode F.