Answer the question
In order to leave comments, you need to log in
How to replace a varying string in a file via .cmd?
There is a file that contains a fragment HOST='pc-name'
Anything can be used instead of pc-name.
You need to find this fragment and replace it with HOST='%COMPUTERNAME%'
Done through the .cmd file
Answer the question
In order to leave comments, you need to log in
you are not the only one .
Explicitly or implicitly , you need to use PowerShell. You can also do this:
$file_path=".\temp.txt"
(Get-Content $file_path) -replace "HOST='[\w\-\d]+'", "HOST='%COMPUTERNAME%'" | out-file -encoding ascii $file_path
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question