linux grep 命令没有返回准确的结果
linux grep command is not returning accurate results
grep 命令没有返回准确的结果。
我有一个包含一些 html 内容的文本文件。我想使用 grep command.the 获取特定单词的计数 grep 命令未返回准确 results.OS - Red Hat Enterprise Linux 服务器版本 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
实际结果:count - 1
注意 "accurate" 和 "desired." 之间的区别 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.
所以它计算一行有匹配,这就是它告诉你的。
grep 命令没有返回准确的结果。
我有一个包含一些 html 内容的文本文件。我想使用 grep command.the 获取特定单词的计数 grep 命令未返回准确 results.OS - Red Hat Enterprise Linux 服务器版本 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
实际结果:count - 1
注意 "accurate" 和 "desired." 之间的区别 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.
所以它计算一行有匹配,这就是它告诉你的。