Joke Collection Website - Blessing messages - How to use the CMD command to rewrite the third line of a text file? For example, enter nihao into the third line of the text.

How to use the CMD command to rewrite the third line of a text file? For example, enter nihao into the third line of the text.

You can only use batch processing to write this, and the number of lines in the original file must not be too many, otherwise the running speed will be very slow

Copy the following command to text file and save it as a file with the extension bat, for example 1.bat

In the following command, 111.txt is the text file you need to replace, 222.txt is the temporary file, pay attention to the space after echo Not too much

input replace row: Enter the line number you want to rewrite

input replace text: Enter the content you want to rewrite

type 111.txt show rewriting text file after

@echo off

setlocal EnableDelayedExpansion

set /p row=input replace row:

set /p strtext =input replace text:

set i=0

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

set / a i+=1

if !i! == %row% (

echo %strtext% >>222.txt

) else (

echo %%a >>222.txt

)

)

del 111.txt

ren 222. txt 111.txt

type 111.txt

echo on