grep 在几个文件上使用时只会失败

Rei*_*eid 5 grep

在过去的 30 分钟里,我一直在努力让它正常工作。grep并不是最难使用的东西,所以我有点困惑为什么这不起作用。

我尝试使用的文件grep是简单的 XHTML 日志文件。他们的名字的格式是name@domain.com.html,虽然我认为这无关紧要,而且里面是简单的XHTML。

我复制了一个这样的日志文件,testfile以便您可以看到一些命令的输出以及为什么它让我感到困惑:

[~/.chatlogs_windows/dec] > whoami
reid
[~/.chatlogs_windows/dec] > type grep
grep is /bin/grep
[~/.chatlogs_windows/dec] > uname -a
Linux reid-pc 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:32:27 UTC 2010 x86_64 GNU/Linux
[~/.chatlogs_windows/dec] > cat /etc/issue
Linux Mint 10 Julia
[~/.chatlogs_windows/dec] > ls -lh testfile
-rw-r--r-- 1 reid reid  63K 2011-01-10 12:45 testfile
[~/.chatlogs_windows/dec] > tail -3 testfile 
</body>
</html>
[~/.chatlogs_windows/dec] > file testfile
testfile: XML document text
[~/.chatlogs_windows/dec] > grep html testfile 
[~/.chatlogs_windows/dec] > grep body testfile 
[~/.chatlogs_windows/dec] > grep "</html>" testfile 
[~/.chatlogs_windows/dec] > grep "</body>" testfile
[~/.chatlogs_windows/dec] > cat testfile | grep html
[~/.chatlogs_windows/dec] > cat testfile | wc -l
231
[~/.chatlogs_windows/dec] > cat testfile | tail -3
</body>
</html>
[~/.chatlogs_windows/dec] > chmod a+rw testfile && ls -lh | grep testfile
-rw-rw-rw- 1 reid reid  63K 2011-01-10 12:45 testfile
[~/.chatlogs_windows/dec] > grep html testfile
Run Code Online (Sandbox Code Playgroud)

这就是我正在尝试做的。我只想使用grep -ri query .in ~/.chatlogs_windows,它通常对我来说非常有效......但由于某种原因,它完全无法通过这些文件。

如果重要的话,我从我的 Windows 7 分区复制了这些文件。但是我 chown'd 它们并给了自己所有适当的权限,其他程序(如cat)似乎可以很好地读取它们。我还将 testfile 复制到 testfile_unix 并转换了行尾并尝试过,但它也不起作用。

我正在使用 zsh,但我在 bash 上尝试过,但也失败了。此外,grep 工作正常:我在我的文档文件夹中试用了它,它工作得很好。

如果您需要更多信息,请告诉我。我试着用谷歌搜索,但我发现 grep 没有理由根本不起作用。提前致谢。

Red*_*ick 7

grep 工具无法识别 UTF-16 文件编码。

  • 天才!对于将来可能遇到此问题的其他任何人,我使用命令 `iconv -f UTF-16 -t UTF-8 testfile &gt; testfile_enc` 将其转换并从那里进行测试。不过,如果 grep 会通知您,而不是默默地失败,那就太好了。 (2认同)