windows 将文本文件过滤为新的文本文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8297706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:32:47  来源:igfitidea点击:

Filter a text file into a new text file

windowsfilteringtext-files

提问by Strontium_99

Sorry about the dummy question here.

很抱歉这里的虚拟问题。

Under Windows I would like to be able to filter one .txt file into a new one. Filtering all lines that contain a specific string.

在 Windows 下,我希望能够将一个 .txt 文件过滤成一个新文件。过滤包含特定字符串的所有行。

I know this could well be a really easy one, but would really appreciate a few pointers please.

我知道这很可能是一个非常简单的方法,但非常感谢您的指点。

回答by RichieHindle

Use the findstrcommand:

使用findstr命令:

findstr my-string filename > new-file

findstr /?will give you a usage message telling you how to use findstr(including the /Vswitch if you wanted to filter lines outrather than filtering them in.)

findstr /?会给你一个用法消息,告诉你如何使用findstr(包括/V如果你想过滤线开关出来,而不是过滤它们)。

Or if you're familiar with grepand wishing you had it on Windows, install Cygwin. :-)

或者,如果您熟悉grep并希望在 Windows 上拥有它,请安装Cygwin。:-)

回答by Neil Thompson

Powershell has some neat string comparison features. You can pipe the output to a new file.

Powershell 有一些简洁的字符串比较功能。您可以将输出通过管道传输到新文件。

^^ There are some better links as to how to use Powershell - but I can't find them this minute. If you go the Powershell route there are lots of examples on the internet.

^^ 关于如何使用 Powershell 有一些更好的链接 - 但我现在找不到它们。如果你走 Powershell 路线,互联网上有很多例子。

回答by Ben

There's a logfile filtering utility Logfilter (www.casstor.com), that can easily do this. You can define multiple filter strings as well as use regular expressions in your filters. I think it might be what you're looking for.

有一个日志文件过滤实用程序 Logfilter (www.castor.com),可以很容易地做到这一点。您可以定义多个过滤器字符串以及在过滤器中使用正则表达式。我想这可能是你要找的。