【发布时间】:2015-06-02 06:28:36
【问题描述】:
我在一个 txt 文件中有一个需要操作的路径,例如:
C:\Jenkins\Automation\Blah\Foo\Bar\646433\Schema\test\473289_12321.ps1 C:\Jenkins\Automation\Blah\Foo\Bar\2112\Schema\QA\473289_123211.ps1
我想替换第 7 个反斜杠之前的所有内容,然后将其替换为 C:\Question。我正在通过以下方式在 Powershell 中做类似的事情:
(Get-Content $FullEnvSQLFilePath) | #get the content
Foreach-Object {$_ -replace [Regex]::Escape($StringToReplace), "$StringReplaceValue"} | #look for the string and replace
当我知道要查找的确切措辞时,这很好用。我们现在不知道这一点,但我们希望删除第 7 个反斜杠之前的所有内容并将其替换为一个值。倒序也可以。通过子字符串执行此操作,我无法在 Powershell 中获得太多运气。谢谢。
【问题讨论】:
-
谢谢 Vesper,让我看看。
标签: powershell