编写批处理变量转化为具体行的文本文件 [英] Write batch variable into specific line in a text file
本文介绍了编写批处理变量转化为具体行的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个批处理文件,我需要一个变量写入一个文本文件中的特定行,并覆盖什么是在该行的所有准备。我有code来读取文件中的特定行也许我可以切换它周围还写?
I have a batch file where I need to write a variable into a specific line of a text file and override what is all ready in that line. I have the code to read specific lines from the file maybe I could switch it around to also write?
阅读线code:
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (variables.txt) do (
set /a N+=1
set v!N!=%%a
)
set variable1=!v1!
set variable2=!v2!
set variable3=!v3!
set variable4=!v4!
我试图添加回声%变量1%GT; !V4!
类似的东西,但它不工作。
I've tried to add echo %variable1% > !v4!
something like that but it doesn't work.
推荐答案
我想通了!这里是code为别人谁可能永远都需要它。
I figured it out!! Here is the code for anyone else who might ever need it.
@echo off
setlocal enableextensions enabledelayedexpansion
set inputfile=variables.txt
set tempfile=%random%-%random%.tmp
copy /y nul %tempfile%
set line=0
for /f "delims=" %%l in (%inputfile%) do (
set /a line+=1
if !line!==4 (
echo WORDS YOU REPLACE IT WITH>>%tempfile%
) else (
echo %%l>>%tempfile%
)
)
del %inputfile%
ren %tempfile% %inputfile%
endlocal
这篇关于编写批处理变量转化为具体行的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文