Regex – 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

Best Solution

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 '^\*'}