Filter a text file into a new text file

荒凉一梦 提交于 2019-12-06 01:48:34

问题


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.

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


回答1:


Use the findstr command:

findstr my-string filename > new-file

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

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




回答2:


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

^^ 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.




回答3:


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.



来源:https://stackoverflow.com/questions/8297706/filter-a-text-file-into-a-new-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!