gpt4 book ai didi

linux grep 命令没有返回准确的结果

转载 作者:太空宇宙 更新时间:2023-11-04 04:43:16 25 4
gpt4 key购买 nike

grep 命令未返回准确的结果。

我有一个文本文件,其中包含一些 html 内容。我想使用 grep 命令获取特定单词的计数。grep 命令未返回准确的结果。操作系统 - Red Hat Enterprise Linux Server 版本 6.6(圣地亚哥)

下面是输入文件test.txt的内容。该文件出现了两次“Tomcat”一词

<html><title>Tomcat Server</title><body><font face="Verdana, Arial" size="-1"><p>Tomcat Server</p></body></html>

grep命令
cat test.txt|grep -c Tomcat
cat test.txt|grep -c "Tomcat"

注意:无论带引号还是不带引号,结果都是相同的

预期结果:计数 - 2
实际结果:计数 - 1

最佳答案

请注意“准确”和“期望”之间的区别。 grep 手册页谈到了 -c 标志:

Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines.

所以它计算的是一行有一个匹配,这就是它告诉你的。

关于linux grep 命令没有返回准确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54188508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com