[英]How to count exact match of certain patterns in a text file using linux shell command?
I want to find the count of certain pattern in a text file which contains lot of mixed patterns also using linux shell command. 我想使用linux shell命令在一个包含很多混合模式的文本文件中找到某些模式的计数。
I have a text file which contains below patterns, 我有一个包含以下模式的文本文件,
[--------------]
[+--------------+]
[+----------+------------+--------------------+]
[+---------------------+---------------------+]
How to find exact count of only first pattern [--------------]
? 如何找到仅第一个模式
[--------------]
确切计数?
Note: Don't include square bracket as a pattern. 注意:请勿包括方括号作为样式。 Only special character inside square bracket is a pattern.
方括号内只有特殊字符是图案。
cat ./file | 猫./file | sed -e 's/\\]/\\]\\n/' |grep "\\[--------------\\]" -c
sed -e's / \\] / \\] \\ n /'| grep“ \\ [-------------- \\]” -c
cat reads file 猫读文件
sed replace ] with ]\\n sed用] \\ n替换]
grep searches every line for your expression and prints the number of lines -c grep在每一行中搜索您的表达式并显示行数-c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.