Batch file 批处理文件将特定行从conf文件复制到另一个conf文件
使用批处理文件 text1.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=" %%
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