bash - grep 数字范围

标签 bash count grep

对于下面的文本,我需要计算括号之间的数字在 [10-20] 范围内的行数。

    This function's cyclomatic complexity is too high. (1)
    This function's cyclomatic complexity is too high. (2)
    This function's cyclomatic complexity is too high. (3)
    This function's cyclomatic complexity is too high. (4)
    This function's cyclomatic complexity is too high. (5)
    This function's cyclomatic complexity is too high. (6)
    This function's cyclomatic complexity is too high. (7)
    This function's cyclomatic complexity is too high. (8)
    This function's cyclomatic complexity is too high. (9)
    This function's cyclomatic complexity is too high. (10)
    This function's cyclomatic complexity is too high. (12)
    This function's cyclomatic complexity is too high. (13)
    This function's cyclomatic complexity is too high. (14)
    This function's cyclomatic complexity is too high. (15)
    This function's cyclomatic complexity is too high. (16)
    This function's cyclomatic complexity is too high. (17)

我正在尝试以下命令:

cat log.txt | grep -c "This function's cyclomatic complexity is too high. ([10-20])"
cat log.txt | grep -c "This function's cyclomatic complexity is too high. ([10,11,12,13,14,15,16,17,18,20])"

但是没用。正确的做法是什么?

最佳答案

grep -c "(1[0-9])\|(20)" filename

关于bash - grep 数字范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47330069/

相关文章:

SQL关于计数的问题

Laravel MySQL 按计数排序

bash - bash 函数可以在不同的脚本中使用吗?

linux - 如何使用 bash 脚本关闭所有终端,在每个终端中有效地按 Ctrl+Shift+Q

Ruby:在方法内递增

linux - diff 的奇怪行为 |搜索引擎优化 | sed

linux - 如何获得最常出现的 unix 实用程序

bash - 使用 pcregrep -M 搜索多行字符串

bash - bash中未设置和空变量之间的区别

bash - 如何以 root 身份打开桌面条目?