@powershell -command sls "succeeded" pol_inst.log
給我選擇字符串命令返回的文件名,行號和文字,但我只想要的文字
pol_inst.log:259: Security Gateway policy installation succeeded for:
我不想
pol_inst.log:259:
,似乎我不能找到一個簡單的答案
@powershell -command sls "succeeded" pol_inst.log
給我選擇字符串命令返回的文件名,行號和文字,但我只想要的文字
pol_inst.log:259: Security Gateway policy installation succeeded for:
我不想
pol_inst.log:259:
,似乎我不能找到一個簡單的答案
Select-String "succeeded" pol_inst.log | ForEach-Object Line
或者它的命令行調用:
@powershell -command Select-String "succeeded" pol_inst.log ^| ForEach-Object Line
發生這種情況是因爲Select-String
會返回一個MatchInfo
對象的集合。除了結果之外,這些內容還包含很多內容。
簡單的解決方法是使用.Line
財產像這樣,
select-string -path c:\myFile -pattern "myPattern" | % { $_.line }
展開MatchInfo
對象的Line
屬性,Select-String
生產:
Select-String ... | Select-Object -Expand Line
什麼是「@」thingie應該做的? –
@JaquelineVanek這是命令提示符下的回顯字符。他從批處理文件或'cmd.exe'調用。 –