在 Windows 中 grep unicode 文本文件的免费程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1196883/
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
Free program to grep unicode text files in Windows?
提问by jacobsee
I have a collection of unicode text files (exported from regedit) and I'd like to pull out all the lines with a certain text on them.
我有一组 unicode 文本文件(从 regedit 导出),我想拉出所有带有特定文本的行。
I've tried Grep for Windowsand findstr but both can't seem to handle the unicode encoding. My results are empty, but when I use the -v option (show non-matching lines), the output shows a NUL between each character.
我已经尝试过Windows 版的 Grep和 findstr,但两者似乎都无法处理 unicode 编码。我的结果是空的,但是当我使用 -v 选项(显示不匹配的行)时,输出会在每个字符之间显示一个 NUL。
Are there any free options to perform a simple grep on Unicode files in Windows?
是否有任何免费选项可以在 Windows 中对 Unicode 文件执行简单的 grep?
回答by Joey
Well, while findstr
can't handle Unicode files directly, type
does and findstr
actually handles Unicode inputwithout problems.
好吧,虽然findstr
不能直接处理 Unicode 文件,type
但findstr
确实可以毫无问题地处理 Unicode输入。
So what you need to do would just be
所以你需要做的就是
type myfile.txt | findstr /c:"I'm searching for this"
> type uc-test.txt Unicode test. ??ü? Another line Something else > findstr "Something" uc-test.txt > findstr /v "Something" uc-test.txt ■U n i c o d e t e s t . ? ÷ 3 ? A n o t h e r l i n e S o m e t h i n g e l s e > type uc-test.txt | findstr "Another" Another line
回答by jacobsee
回答by chappar
If you have notepad++, you can use "Find in Files..." option to search unicode files.
如果您有记事本++,则可以使用“在文件中查找...”选项来搜索 unicode 文件。
回答by andersonbd1
definitely go with cygwin (using x server) - the latest supports utf8. At my last gig, I was doing a lot of work with CJK characters. Using cygwin's x server, you can search on any characters and display any characters that you have a fixed width font for. Also check out od and xxd which makes it easy to enter your searches using hex characters eg: $ echo '?' | grep $(echo '3f' | xxd -p -r)
绝对使用 cygwin(使用 x 服务器)-最新版本支持 utf8。在我的最后一场演出中,我做了很多与 CJK 角色有关的工作。使用 cygwin 的 x 服务器,您可以搜索任何字符并显示具有固定宽度字体的任何字符。还可以查看 od 和 xxd 这使得使用十六进制字符输入搜索变得容易,例如:$ echo '?' | grep $(echo '3f' | xxd -p -r)
回答by Master0K
I use grep.exe from http://unxutils.sourceforge.net/with "chcp 65001" command conjunction in the Windows command line.
我将http://unxutils.sourceforge.net/ 中的grep.exe与 Windows 命令行中的“chcp 65001”命令结合使用。
回答by stankovski
回答by dalloliogm
I have not used windows for years, but I know two alternatives to grep which are written in interpreted language and therefore should run on any platform:
我已经多年没有使用 Windows,但我知道 grep 的两种替代方案,它们是用解释性语言编写的,因此应该在任何平台上运行:
Both are command-line tool, but I assume you already have a solution for this if you have used grep for windows.
两者都是命令行工具,但我假设如果您在 Windows 上使用了 grep,那么您已经有了解决方案。
Have a look at them, I am sorry I can't help a fellow grepper better than this.
看看他们,很抱歉,我无法帮助其他人比这更好。
回答by user5132533
I believe the most convient free program you need in Windows is Powershell. For example:
我相信您在 Windows 中需要的最方便的免费程序是 Powershell。例如:
Get-ChildItem -Recurse -path c:\temp\*.c |Select-String -pattern "myunicodestring"
Get-ChildItem -Recurse -path c:\temp\*.c |Select-String -pattern "myunicodestring"
Or if you just only want to search in a directory (not in subdirectory):
或者,如果您只想在目录中搜索(而不是在子目录中):
Select-String -path "c:\mydir\*.log" -pattern "error"
Select-String -path "c:\mydir\*.log" -pattern "error"
回答by Atmocreations
is cygwin an option for you? maybe the grep that is builtin behaves better than the one you tried...
cygwin 是您的选择吗?也许内置的 grep 比你试过的那个表现更好......
regards
问候