问题描述
我有一个生成的 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文件中的某些行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!