如何删除用户定义的线在批处理文件 [英] How to remove user defined line in a batch file

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

问题描述

我想删除通过在一个文件中的用户输入指定的行那么保存该文件相同的文件名。

I want to remove specific lines entered by the user in one file then save this file same as the file name.

例如我有这样的code

For example I have this code

for /f "tokens=2,3" %%a in ('type c:\files.txt') do 
(
    Set /p line= ENTER THE LINE YOU WANT TO DISREGARD:
    findstr /v /r /c:"^[!line!]*$" "c:\file1\%%a" > "c:\file2\%%a"      ----> For Column2 (Name1)
    findstr /v /r /c:"^[!line!]*$" "c:\file1\%%a" > "c:\file2\%%a"      ----> For Column3 (Name2) 
)

Files.txt包含了其他文件的文件名。然后在我的的声明,它打开Files.txt(列2和栏3)显示所有文件

Files.txt contains filenames of other files. Then in my for statement, It opens all the files indicated in Files.txt (Column2 and Column3)

files.txt示例内容:

files.txt sample contents:

Name    Name1.txt   Name2.txt
Age     Age1.txt    Age2.txt
Add     Add1.txt    Add2.txt

在我运行该批处理文件,为什么它会自动删除文件中的所有文本?另外,我怎么能删除一个提示定义了多个用户?我能得到它用逗号隔开?

Once I run the batch file,why it automatically deletes all the text inside the file?. Also, How can I delete multiple user defined in one prompt? Can I have it separated by comma?

推荐答案

我已经解决了这个问题。

I already solved the problem

    Set /p line= enter line to remove :
for /f "tokens=2,3" %%a in ('type c:\file\files.txt') do (

Type c:\file\aaa\%%a  | findstr /I /V /C:"!line!" > c:\file\aaa\OUTPUT\%%a 
Type c:\file\bbb\%%b  | findstr /I /V /C:"!line!" > c:\file\bbb\OUTPUT\%%b 

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

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