1. 首页 > 科技

求大神给个bat批处理代码完成TXT文件中特定位置的数字改变 bat命令批处理txt文件

求大神给个bat批处理代码完成TXT文件中特定位置的数字改变bat命令批处理txt文件

用Bat文件修改TXT内容,主要是在特殊行位置加入一些内容

@echo off&&setlocal enabledelayedexpansion

if exist b.txt del b.txt/f/q

set /p lines=在第几行后添加内容:

set /p word=添加的内容:

set n=0

for /f "tokens=* delims=" %%a in (a.txt) do (

set /a n+=1

>>b.txt echo %%a

if "!n!"=="!lines!" >>b.txt echo %word%

)

start b.txt

***************************************************************************************************

星号上面的内容另存为xxx.bat,要修改的文件存为a.txt,放在同级目录下运行,有问题HI我

如何让BAT只修改文件的指定位置!

@echo off

cd /d C:\Program Files\TalesRunnerKR\

copy Option.txt Option.txt.bak

for /f "delims=" %%a in (Option.txt) do (

if not "%%a" equ "ScreenWindowMode=Normal" (

echo.%%a>>test.txt

) else (

echo ScreenWindowMode=True>>test.txt

)

)

move test.txt Option.txt

怎样用批处理截取TXT文档指定位置的字符,并生成新的TXT文档

test.bat 文件内容:

@echo off

setlocal enabledelayedexpansion

set line=0

for /f "tokens=1,2* delims=:" %%i in (ding.txt) do (

set /a line+=1

echo Memory:%%j > !line!.txt

)

------------------------

下面是在命令行下的测试:

C:\Documents and Settings\seesea\桌面\test>type test.bat

@echo off

setlocal enabledelayedexpansion

set line=0

for /f "tokens=1,2* delims=:" %%i in (ding.txt) do (

set /a line+=1

echo Memory:%%j > !line!.txt

)

C:\Documents and Settings\seesea\桌面\test>test.bat

C:\Documents and Settings\seesea\桌面\test>type ding.txt

Memory: 2048MB RAM

Available OS Memory: 1892MB RAM

C:\Documents and Settings\seesea\桌面\test>type 1.txt

Memory: 2048MB RAM

C:\Documents and Settings\seesea\桌面\test>type 2.txt

Memory: 1892MB RAM

------------------------

求批处理批量替换txt特定字符\/|:<>?*和行首Tab

@echo off

set "fs=%*"

if "%fs%"=="" set/p fs=用鼠标拖入要处理的文件(直接回车取当前文件夹所有txt文件):

if "%fs%"=="" for /f "delims=" %%i in ('dir/b *.txt')do call set fs=%%fs%% "%%~fi"

for %%i in (%fs%)do (

cd/d "%%~dpi"

(for /f "tokens=1* delims= :" %%a in ('findstr/n .* "%%~nxi"')do (

set "h=y%%b"

setlocal enabledelayedexpansion

set "h=!h:\=╲!"

set "h=!h:/=╱!"

set "h=!h:|=‖!"

set "h=!h::=:!"

set "h=!h:<=《!"

set "h=!h:>=》!"

set "h=!h:?=?!"

set n=1&set n.=2&call :yky

echo.!h:~1!

endlocal))>temp.txt

move temp.txt "%%~nxi"

)

pause

goto :eof

:yky

if "!h:~%n%!"=="" goto :eof

if "!h:~%n%,1!"=="*" (

set h=!h:~,%n%!﹡!h:~%n.%!)

set/a n+=1,n.+=1

goto :yky