通过批处理文件删除txt文件中的某些行

编程入门 行业动态 更新时间:2024-10-27 21:10:26
本文介绍了通过批处理文件删除txt文件中的某些行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个生成的 txt 文件.这个文件有一些多余的行,需要删除.每行需要删除的行中有两个字符串之一;错误"或参考".这些标记可能出现在行中的任何位置.我想删除这些行,同时保留所有其他行.

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

良好的数据线C:DirectoryERRORmyFile.dll 的坏行另一个很好的数据线坏线:REFERENCE好线

我希望文件最终是这样的:

良好的数据线另一个很好的数据线好线

TIA.

解决方案

使用以下内容:

type file.txt |findstr/v 错误 |findstr/v 参考

这样做的好处是可以使用 Windows 操作系统中的标准工具,而不必查找和安装 sed/awk/perl 等.

请参阅以下文字记录以了解它的运行情况:

C:>输入文件.txt良好的数据线C:DirectoryERRORmyFile.dll 的坏行另一个很好的数据线坏线:REFERENCE好线C:>输入文件.txt |findstr/v 错误 |findstr/v 参考良好的数据线另一个很好的数据线好线

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.

So, if the txt file looks like this:

Good Line of data bad line of C:DirectoryERRORmyFile.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.

解决方案

Use the following:

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

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:DirectoryERRORmyFile.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文件中的某些行

本文发布于:2023-05-27 19:32:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/300554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批处理文件   文件   txt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!