如何通过Powershell搜索文件夹中的.token文件并替换字符前后的“__”?
How to search .token files in a folder and replace "__" in front and end of character via Powershell?
我想搜索具有以下模式字符串的 .token 文件的文件 __[characters]__
并通过 PowerShell 执行以下操作:
- 删除带有“#{”的任何字符前面的“__”(两个下划线)
- 删除同一字符末尾的“__”(两个下划线)并替换为“}”
例如:
__STAGE__
to
#{STAGE}
我正在将 RM 令牌文件迁移到 Octopus Deploy,需要通过脚本进行清理步骤。
以最基本的方式并假设将令牌文件装入内存没有问题:
$TokenFiles = Get-ChildItem *.token
foreach ($file in $TokenFiles) {
$NewContent = Get-Content $file.FullName -Raw
$NewContent = $NewContent -replace '__(.*?)__', '#{}'
Set-Content $file.FullName -Value $NewContent
}
我想搜索具有以下模式字符串的 .token 文件的文件 __[characters]__
并通过 PowerShell 执行以下操作:
- 删除带有“#{”的任何字符前面的“__”(两个下划线)
- 删除同一字符末尾的“__”(两个下划线)并替换为“}”
例如:
__STAGE__
to
#{STAGE}
我正在将 RM 令牌文件迁移到 Octopus Deploy,需要通过脚本进行清理步骤。
以最基本的方式并假设将令牌文件装入内存没有问题:
$TokenFiles = Get-ChildItem *.token
foreach ($file in $TokenFiles) {
$NewContent = Get-Content $file.FullName -Raw
$NewContent = $NewContent -replace '__(.*?)__', '#{}'
Set-Content $file.FullName -Value $NewContent
}