【发布时间】:2019-07-03 17:38:26
【问题描述】:
我有一个文本文件,其中包含某些字符串,例如 12344KB、1231232KB 等。 我必须使用 powershell 将这些以 KB 结尾的单词更改为 10KB。 我刚开始学习powershell,如果有人可以帮我提供脚本,那将非常有帮助。
我尝试了类似下面的代码。
((Get-Content -path C:\test.txt) -replace '*KB','10KB') | Set-Content -Path C:\test.txt
实际:值为 12344KB、1231232KB
预期:值为 10KB、10KB
【问题讨论】:
-
试试
-replace '\b\d+KB\b', '10KB'。 -
@Theo 可能会将其作为答案提交
-
@MathiasR.Jessen 你是对的。 cmets中回答的问题太多
标签: powershell powershell-2.0 powershell-3.0 powershell-4.0