Replacing text in cmd using a substring

Viewed 46

I need to open a file and search for substring. Then replace the other text on the same line.

Have to search for text: #define MyAppVersion and replace the version inside the double quotes (this is dynamic, will be fetched from a different file).

#define MyAppVersion "1.0.0"

So here is what I currently have:

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"

But this only outputs like this:

#define MyAppVersion 1.1.0 "1.0.0"

How can I change the entire line then without using any 3rd party plugins?

Thanks!

1 Answers

Finally got it to work,

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

The .+ will match the rest of this line

Related