E
E
Eugene2017-05-29 15:26:25
Command line
Eugene, 2017-05-29 15:26:25

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

4 answer(s)
A
Alexander Aksentiev, 2017-05-29
@Sanasol

www.guidingtech.com/2051/find-computer-name-comman...

F
Fat Lorrie, 2017-05-29
@Free_ze

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

0
074909, 2018-01-20
@074909

If you don't want to deploy posh to xp, then take sed from gnuwin32.

P
pxaJJ, 2018-07-07
@pxaJJ

Use CHGSTR.EXE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question