开发者

Replace a string at a fixed position in a text file with the output of a command with cmd

开发者 https://www.devze.com 2023-04-08 09:02 出处:网络
I wants to replace the QUICKSERVER string in line 3 of my text file which is located at c:\\BR.txt with the output from the hostname command in Windows CMD. hostname is a Windows command which returns

I wants to replace the QUICKSERVER string in line 3 of my text file which is located at c:\BR.txt with the output from the hostname command in Windows CMD. hostname is a Windows command which returns the system name.

C:\>hostname
QUICKSERVER

my text file is:

开发者_C百科  userName=Administrator
  password=
  CMS=QUICKSERVER:6400
  authentication=secEnterprise

Please find the command which I can execute in the Windows command line to replace the hostname with QUICKSERVER.


The host name can also be found in the %computername% environment variable, so you don't need the hostname command.

@echo off
setlocal enabledelayedexpansion
for %%L in (c:\br.txt) do (
  set "LINE=%%L"
  set "LINE=!LINE:QUICKSERVER=%COMPUTERNAME%!"
  echo !LINE!
) > C:\br2.txt
move /y C:\br2.txt c:\br.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消