计算日志文件中单词 [error] 和 [notice] 的出现次数

发布于 2025-01-10 07:26:19 字数 323 浏览 4 评论 0原文

我在 Linux Ubuntu 中遇到一个小问题,试图计算我这里的日志文件中单词 [error] 和 [notice] 的出现次数。这是我到目前为止所尝试过的:

grep -o -i '[error]' apache.log | wc -l

使用 grep 和这些选项来计数,就好像行不重要一样,并且:

grep -o -i '[notice]' apache.log | wc -l

但是,我没有得到给定的答案,并且我不确定我的命令行出了什么问题,如果有人能给我关于这一切的意见。

谢谢!

I am facing a small problem over here in Linux Ubuntu trying to count the number of occurrences of the words [error] and [notice] in a log file that I have over here. Here is what I have tried so far :

grep -o -i '[error]' apache.log | wc -l

Using grep and these options to count as if lines don't matter, and :

grep -o -i '[notice]' apache.log | wc -l

However, I don't arrive to the given answer, and I am not sure what is wrong with my command line, if someone could give me an input on all of this.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿看小鸭子会跑 2025-01-17 07:26:19

您需要

grep -oi '\[notice]' apache.log | wc -l

详细信息

  • -o - 仅输出匹配的文本
  • -i - 不区分大小写的匹配
  • \[notice] -一个文字 [notice] 字符串(由于该模式被解析为 POSIX BRE 模式,因此您需要转义 [)。

或者,匹配固定的字符串模式:

grep -oiF '[notice]' apache.log | wc -l

其中 -F 将强制 grep 搜索固定的 [notice] 字符串。

You need

grep -oi '\[notice]' apache.log | wc -l

Details:

  • -o - output matched texts only
  • -i - case insensitive matching
  • \[notice] - a literal [notice] string (since the pattern is parsed as a POSIX BRE pattern, you need to escape [).

Or, to match a fixed string pattern:

grep -oiF '[notice]' apache.log | wc -l

where -F will force grep to search for a fixed [notice] string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文