grep 中的仅整数通配符
integer-only wildcards in grep
我有一个输出集合字符串的命令,如下所示:
json.formats[0]].url = "https://example.com/ar.html"
json.formats[1].url = "https://example.com/es.html"
json.formats[2s].url = "https://example.com/ru.html"
json.formats[3].url = "https://example.com/pt.html"
json.formats[73].url = "https://example.com/ko.html"
json.formats[1502].url = "https://example.com/pl.html"
(还有更多实例,但为了简单起见,它们已被删除)
我可以使用下面的命令
myCmd | grep -e 'json\.formats\[.*\]\.url\ \=\ '
但是我只希望通配符匹配整数,并排除非整数匹配。它给了我以下内容:
json.formats[0]].url = "https://example.com/ar.html"
json.formats[1].url = "https://example.com/es.html"
json.formats[2s].url = "https://example.com/ru.html"
json.formats[3].url = "https://example.com/pt.html"
json.formats[73].url = "https://example.com/ko.html"
json.formats[1502].url = "https://example.com/pl.html"
我真正想要的是:
json.formats[1].url = "https://example.com/es.html"
json.formats[3].url = "https://example.com/pt.html"
json.formats[73].url = "https://example.com/ko.html"
json.formats[1502].url = "https://example.com/pl.html"
谢谢 :-)
您可以使用:
myCmd | grep -E 'json\.formats\[[[:digit:]]+\]\.url = '
或:
myCmd | grep -E 'json\.formats\[[0-9]+\]\.url = '
对于大多数语言环境,[[:digit:]]
等同于 [0-9]
。
我有一个输出集合字符串的命令,如下所示:
json.formats[0]].url = "https://example.com/ar.html"
json.formats[1].url = "https://example.com/es.html"
json.formats[2s].url = "https://example.com/ru.html"
json.formats[3].url = "https://example.com/pt.html"
json.formats[73].url = "https://example.com/ko.html"
json.formats[1502].url = "https://example.com/pl.html"
(还有更多实例,但为了简单起见,它们已被删除)
我可以使用下面的命令
myCmd | grep -e 'json\.formats\[.*\]\.url\ \=\ '
但是我只希望通配符匹配整数,并排除非整数匹配。它给了我以下内容:
json.formats[0]].url = "https://example.com/ar.html"
json.formats[1].url = "https://example.com/es.html"
json.formats[2s].url = "https://example.com/ru.html"
json.formats[3].url = "https://example.com/pt.html"
json.formats[73].url = "https://example.com/ko.html"
json.formats[1502].url = "https://example.com/pl.html"
我真正想要的是:
json.formats[1].url = "https://example.com/es.html"
json.formats[3].url = "https://example.com/pt.html"
json.formats[73].url = "https://example.com/ko.html"
json.formats[1502].url = "https://example.com/pl.html"
谢谢 :-)
您可以使用:
myCmd | grep -E 'json\.formats\[[[:digit:]]+\]\.url = '
或:
myCmd | grep -E 'json\.formats\[[0-9]+\]\.url = '
对于大多数语言环境,[[:digit:]]
等同于 [0-9]
。