Powershell 使用子字符串替换cmd中的文本

Powershell 使用子字符串替换cmd中的文本,powershell,batch-file,cmd,Powershell,Batch File,Cmd,我需要打开一个文件并搜索子字符串。然后替换同一行上的其他文本 必须搜索文本:#定义MyAppVersion并替换双引号内的版本(这是动态的,将从其他文件获取) 以下是我目前的情况: rem version num to be retrieved elsewhere, set here for simplicity on sample set VER=1.1.0 powershell -Command "(gc sample.iss) -replace '#define MyAppVersion'

我需要打开一个文件并搜索子字符串。然后替换同一行上的其他文本

必须搜索文本:
#定义MyAppVersion
并替换双引号内的版本(这是动态的,将从其他文件获取)

以下是我目前的情况:

rem version num to be retrieved elsewhere, set here for simplicity on sample
set VER=1.1.0
powershell -Command "(gc sample.iss) -replace '#define MyAppVersion', '#define MyAppVersion "%VER%"' | Out-File sample.iss"
但这只会产生如下结果:

#define MyAppVersion 1.1.0 "1.0.0"
我如何在不使用任何第三方插件的情况下更改整个产品线


谢谢

终于成功了

set VER=1.1.0
powershell -Command "(gc sample.iss) -replace '#define MyAppVersion.+', '#define MyAppVersion "\"%VER%"\"' | Out-File mod.iss"

+
将匹配此行的其余部分

好吧,输出与您告诉命令的操作完全一致;我可以想象有一些正则表达式支持。。。
set VER=1.1.0
powershell -Command "(gc sample.iss) -replace '#define MyAppVersion.+', '#define MyAppVersion "\"%VER%"\"' | Out-File mod.iss"