How to use a batch file to delete a line of text i

2019-06-13 07:51发布

I have a bunch of txt files in my D drive which are placed randomly in different locations. Some files also contain symbols. I want a batch file so that I can delete their specific lines completely at the same time without doing it one by one for each file and please refer to a code which does not create a new text file at some other location with the changes being incorporated i.e. I do not want the input.txt and output.txt thing. I just need the original files to be replaced with the changes as soon as I click the batch file.

e.g D:\abc\1.txt D:\xyz\2.txt etc

I want both of their 3rd lines erased completely with a single click and the new file must be saved with the same name in the same location i.e. the new changed text files must replace the old text files with their respective lines removed. Maybe some sort of *.txt thing i.e i should be able to change all the files with the .txt extensions in a drive via a single batch file perhaps in another drive,not placing my batch file into each and every folder separately and then running them. Alternatively a vbs file is also welcomed.

1条回答
地球回转人心会变
2楼-- · 2019-06-13 07:54

This uses a helper batch file called findrepl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697

Place findrepl.bat in the same folder as the batch file below.

It will search for every *.txt file on drive d: and remove line 3.

@echo off
for /r "d:\" %%a in (*.txt) do (
   echo processing "%%a"
   type "%%a"|findrepl /v /o:3:3 >"%%a.tmp"
   move "%%a.tmp" "%%a" >nul
)
pause
查看更多
登录 后发表回答