我有以下文本文件
testA=foo
testB=foobar
testC=Whatever
Run Code Online (Sandbox Code Playgroud)
现在我想提取的值testB是foobar.使用我当前的PowerShell命令,我只能收到整行:
testB=foobar
Run Code Online (Sandbox Code Playgroud)
我的命令是:
Select-String -Path .\test.txt -Pattern "testB=" -List
Run Code Online (Sandbox Code Playgroud)
我可以看到字符串有替换函数,所以你可以testB=用空字符串替换,但我不知道如何实现这一点.
您不必替换任何内容来捕获值.而是将捕获组添加到搜索模式中.然后您就可以访问捕获的值:
(Select-String -Path $scripts.tmp -Pattern "testB=(.*)").Matches.Groups[1].Value
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5399 次 |
| 最近记录: |