计算日志文件中单词 [error] 和 [notice] 的出现次数
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要
详细信息:
-o
- 仅输出匹配的文本-i
- 不区分大小写的匹配\[notice]
-一个文字[notice]
字符串(由于该模式被解析为 POSIX BRE 模式,因此您需要转义[
)。或者,匹配固定的字符串模式:
其中
-F
将强制grep
搜索固定的[notice]
字符串。You need
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:
where
-F
will forcegrep
to search for a fixed[notice]
string.