简体   繁体   English

如何使用Linux Shell命令计算文本文件中某些模式的完全匹配?

[英]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.

相关问题 如何使用 linux 中的连接命令将两个不同长度和不同列的文本文件与 header 匹配 - How to match two different length and different column text file with header using join command in linux 使用Linux Shell正则表达式匹配文件名 - Match file names using Linux Shell regex 是否可以使用 Linux 命令或 shell 脚本根据特定条件删除文件中不需要的行? - Is it possible using a Linux command or shell script to remove unwanted rows in a file based on certain condition? Shell - 如何从具有多种模式的文本文件中删除行? - Shell - How to delete lines from text file with multiple patterns? 如何使用SSH命令将递归目录和文件列表导出到Linux Bash Shell中的文本文件? - How can I export a recursive directory & file listing to a text file in Linux Bash shell with an SSH command? Linux Shell脚本来计算文本文件中char序列的出现? - Linux shell script to count occurance of char sequence in a text file? 使用 sed 在 Linux shell 中模式匹配后替换立即文本 - To replace a immediate text after pattern match in Linux shell using sed 如何在Linux中通过Java执行Shell脚本并保存为文本文件命令 - How to execute shell script and save in text file command through java in linux Linux Shell命令将文本数据从文件复制到另一个文件 - Linux shell command to copy text data from a file to another 如何使用linux命令在文本文件中选择包含信息的行 - How to select rows with information in a text file by using linux command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM