powershell修改文件某一行

创建powershell脚本文件:updateVersion.ps1,内容如下:
param($filepath, $version)

#读文件
$content = Get-Content -Encoding UTF8 $filepath

$newVersion = "$version"

#修改文件
$content = $content -replace ".*", $newVersion

#写文件
$content | Out-File -Encoding UTF8 $filepath

exit 0
调用:
powershell.exe -ExecutionPolicy RemoteSigned -File updateVersion.ps1 d:/pc/parent/pom.xml 5.0.0.100
其中,-Encoding UTF8 参数用于解决读写中文乱码问题。

powershell修改文件某一行最先出现在Python成神之路

版权声明:
作者:cc
链接:https://www.techfm.club/p/22197.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>