【发布时间】:2016-02-02 14:40:08
【问题描述】:
我正在尝试制作一个执行以下操作的脚本:
- 打印文件
- 删除所有空行
- 过滤掉所有不包含“重新分配”一词的行
- 从每行的开头删除所有空格和“>”
在我为第 4 步添加函数之前,一切正常,之后 powershell 会吐出一堆错误。我在这里做错了什么?
PS C:\Users\pzsr7z.000\Desktop\incidentoutput> cat .\csvtest.txt | ? {$_.trim() -ne "" } | sls "^Reassignment$" -Context 1,2 | foreach{ $_.TrimStart(">"," ")}
Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo] does not contain a method named 'TrimStart'.
At line:1 char:90
+ ... 1,2 | foreach{ $_.TrimStart(">"," ")}
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo] does not contain a method named 'TrimStart'.
At line:1 char:90
+ ... 1,2 | foreach{ $_.TrimStart(">"," ")}
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo] does not contain a method named 'TrimStart'.
At line:1 char:90
+ ... 1,2 | foreach{ $_.TrimStart(">"," ")}
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo] does not contain a method named 'TrimStart'.
At line:1 char:90
+ ... 1,2 | foreach{ $_.TrimStart(">"," ")}
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
所有功能都单独工作,当我尝试添加最后一部分时,事情就搞砸了。
【问题讨论】:
-
不包含... ???什么?
标签: windows powershell