如何 grep 具有超过特定数量的特殊字符的行

αԋɱ*_*cαη 4 linux sed awk regular-expression

我想知道从具有超过特定数量的特殊字符的文本中 grep 行的最佳方法是什么。

假设您已经知道每行有 4 个逗号,,并且您想要 grep 包含超过 4 个逗号的行,

例子

hi,hello,how,are,you
catch,me,then,say,hello,then
Run Code Online (Sandbox Code Playgroud)

输出

catch,me,then,say,hello,then
Run Code Online (Sandbox Code Playgroud)

cho*_*oba 5

Perl解决方案:

perl -ne 'print if tr/,// > 4'
Run Code Online (Sandbox Code Playgroud)
  • -n逐行读取文件
  • tr 运算符返回匹配项的数量。

要打印少于 4 行,只需更改><