Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 查找某些字符串序列的出现次数_Linux_String_Grep_Debian_Cat - Fatal编程技术网

Linux 查找某些字符串序列的出现次数

Linux 查找某些字符串序列的出现次数,linux,string,grep,debian,cat,Linux,String,Grep,Debian,Cat,我想使用grep | wc计算文本文件中IP地址192.168.1.10的出现次数 我使用的命令是: cat ./capture.txt|grep "192.168.1.10"|wc -w 返回0,我不知道为什么 以下是my.txt文件的内容: 试试看: grep -Fwo '192.168.1.10' file|wc -l -F使grep将您的模式作为文本字符串而不是正则表达式 -w不包括192.168.1.101或192.168.1.100 -o在一行中列出每个匹配项。grep进行基于

我想使用
grep | wc
计算文本文件中IP地址
192.168.1.10
的出现次数

我使用的命令是:

cat ./capture.txt|grep "192.168.1.10"|wc -w
返回0,我不知道为什么

以下是my.txt文件的内容:

试试看:

grep -Fwo '192.168.1.10' file|wc -l
  • -F
    使grep将您的模式作为文本字符串而不是正则表达式
  • -w
    不包括
    192.168.1.101
    192.168.1.100
  • -o
    在一行中列出每个匹配项。grep进行基于行的匹配,如果您的模式在一行中匹配了两次,则出现次数的结果可能是错误的
  • \。
    搜索点,而不是任何字符
  • \b
    在单词的开头或结尾匹配
  • -c
    返回出现的次数

链接到文本图片是没有用的。将相关文本剪切并粘贴到问题中。这使得它是自包含的,并且易于阅读。很抱歉,拼写错误的cat./capture.txt | grep“192.168.1.10”,但我仍然没有得到预期的效果
cat ./capture.txt | grep "\b192\.168\.1\.10\b" -c