Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理文件将特定行从conf文件复制到另一个conf文件_Batch File - Fatal编程技术网

Batch file 批处理文件将特定行从conf文件复制到另一个conf文件

Batch file 批处理文件将特定行从conf文件复制到另一个conf文件,batch-file,Batch File,使用批处理文件 text1.conf的dynamic_username标记之间是一个动态用户名字符串。我希望它被自动选择并复制到另一个文件TeX2.CONF并替换空白标签插入这里用户名< /C> >/P> text1.conf包含动态\u用户名请尝试以下操作: for /f "tokens=2delims=<>" %%i in ('findstr /i "username" "text1.conf"') do set "string=%%i" (for /f "delims=" %%

使用批处理文件

text1.conf的
dynamic_username
标记之间是一个动态用户名字符串。我希望它被自动选择并复制到另一个文件TeX2.CONF并替换空白标签<代码>插入这里用户名< /C> >/P> text1.conf包含
动态\u用户名
请尝试以下操作:

for /f "tokens=2delims=<>" %%i in ('findstr /i "username" "text1.conf"') do set "string=%%i"
(for /f "delims=" %%i in ('findstr /n "^" "text2.conf"') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:*:=!"
    if "!line!" neq "!line:username=!" set "line=%string%"
    echo(!line!
    endlocal
))>"text2.conf.new"
for/f“tokens=2delims=“%%i in('findstr/i“username”“text1.conf”)do set“string=%%i”
(对于/f“delims=“%%i in('findstr/n“^”text2.conf“)do(
设置“行=%%i”
延迟扩展
设置“行=!行:*=!”
如果“!line!”neq“!line:username=!”设置“line=%string%”
回声(!线!
端部
))>“text2.conf.new”
@ECHO OFF
SETLOCAL
(
对于(text2.conf)DO中的/f“delims=”%%i(
如果“%%i”==”(
FINDSTR/b/e.*.text2.conf.new
FC text2.conf text2.conf.new
后藤:eof
但将删除空行

@ECHO OFF
SETLOCAL
(
FOR /f "delims=" %%i IN (text2.conf) DO (
 IF "%%i"=="<username></username>" (
  FINDSTR /b /e ".*<username>.*</username>.*" <text1.conf
  ) ELSE (ECHO(%%i)
)
)>text2.conf.new

FC text2.conf text2.conf.new

GOTO :eof