简体   繁体   English

在Powershell选择字符串输出中删除以*(星号)开头的行

[英]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 我正在编写代码,以便它找到具有$ control的行,但应删除第一列中以*开头的行

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 提前致谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM