如何使用批处理文件删除一行文本在一堆文本文件? [英] How to use a batch file to delete a line of text in a bunch of text files?

查看:179
本文介绍了如何使用批处理文件删除一行文本在一堆文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在D盘一堆txt文件它们随意放置在不同的位置。有些文件还包含符号。我想一个批处理文件,这样我可以在同一时间完全删除其具体线路没有一个做每个文件并请查阅到code这并不在其他位置与创建一个新的文本文件变化被纳入即我不想input.txt中和output.txt的事情。我只需要原来的文件要与变化尽快更换我点击该批处理文件。

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.

例如
D:\\ ABC \\ 1.TXT
D:\\某某\\ 2.txt等

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

我想他们都3系的一个单一的点击彻底删除,新的文件必须在同一个位置,即新的改变文本文件相同的名称保存必须拆除各自的线替换旧的文本文件。也许某种* .TXT事情即我应该能够通过一个单一的批处理文件或者更改所有在驱动器中的.txt扩展名的文件在另一个驱动器,而不是把我的批处理文件到每一个单独的文件夹,然后运行他们。另外一个VBS文件也表示欢迎。

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.

推荐答案

本使用名为 findrepl.bat 从助手批处理文件 - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697

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

findrepl.bat 在同一文件夹下面的批处理文件。

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

它将搜索驱动器D每* .txt文件:并删除第3行

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

这篇关于如何使用批处理文件删除一行文本在一堆文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆