通过批处理文件删除一个txt文件的某些行 [英] Delete certain lines in a txt file via a batch file

查看:570
本文介绍了通过批处理文件删除一个txt文件的某些行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成的TXT文件。该文件具有一定的线是多余的,并且需要被去除。每个需要去除线具有两个串中的线路中的一个; ERROR或引用。这些令牌可在该行的任何地方出现。我想删除这些线,同时保留所有其他行。

I have a generated txt file. This file has certain lines that are superfluous, and need to be removed. Each line that requires removal has one of two string in the line; "ERROR" or "REFERENCE". These tokens may appear anywhere in the line. I would like to delete these lines, while retaining all other lines.

所以,如果txt文件看起来是这样的:

So, if the txt file looks like this:


Good Line of data
bad line of C:\Directory\ERROR\myFile.dll
Another good line of data
bad line: REFERENCE 
Good line

我想该文件以结束这样的:

I would like the file to end up like this:


Good Line of data
Another good line of data
Good line

TIA。

推荐答案

使用以下内容:

type file.txt | findstr /v ERROR | findstr /v REFERENCE

这有使用标准工具在Windows操作系统,而不必寻找和安装SED / AWK / Perl和这样的优势。

This has the advantage of using standard tools in the Windows OS, rather than having to find and install sed/awk/perl and such.

请参阅下面的谈话它在运行:

See the following transcript for it in operation:


C:\>type file.txt
Good Line of data
bad line of C:\Directory\ERROR\myFile.dll
Another good line of data
bad line: REFERENCE
Good line

C:\>type file.txt | findstr /v ERROR | findstr /v REFERENCE
Good Line of data
Another good line of data
Good line

这篇关于通过批处理文件删除一个txt文件的某些行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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