如何使用 PowerShell 替换文件中每个出现的字符串? [英] How can I replace every occurrence of a String in a file with PowerShell?
本文介绍了如何使用 PowerShell 替换文件中每个出现的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 PowerShell,我想用 MyValue
替换给定文件中所有出现的 [MYID]
.最简单的方法是什么?
Using PowerShell, I want to replace all exact occurrences of [MYID]
in a given file with MyValue
. What is the easiest way to do so?
推荐答案
使用(V3版本):
(Get-Content c:\temp\test.txt).replace('[MYID]', 'MyValue') | Set-Content c:\temp\test.txt
或者对于 V2:
(Get-Content c:\temp\test.txt) -replace '\[MYID\]', 'MyValue' | Set-Content c:\temp\test.txt
这篇关于如何使用 PowerShell 替换文件中每个出现的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文