使用 Tail 和 Grep select 双引号中的特定短语

using Tail and Grep to select a specific phrase within a double quotation

目前我是 tailgrep 实时日志,但想 grep 整个 url 在双引号内 ...

我整理的当前尾巴

tail -F trans.log | grep --color -E -i "https://www.example.com|$"

日志

1.1.1.1 6 - [21/Jan/2022:16:41:21 +0000] "GET /media/catalog/product/cache/####.jpg HTTP/1.1" 304 - "https://www.example.com/customer/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"

期望的输出:

for grep https://www.example.com/customer/ 将在实时日志 Tail

期间突出显示

正在将我的评论转换为答案,以便未来的访问者可以轻松找到解决方案。

你可以使用这个命令:

tail -F trans.log | grep --color -ioE 'https://www\.example\.com[^"]*'

模式 https://www\.example\.com[^"]* 匹配以 https://www.example.com 开头后跟 0 个或多个非 " 字符的子字符串。