Home > Software engineering >  using Tail and Grep to select a specific phrase within a double quotation
using Tail and Grep to select a specific phrase within a double quotation

Time:01-22

currently I am tail and grep a live log but would like to grep the entire url within the double quotation ...

Current tail i've put together

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

Log

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"

Desired output:

for grep https://www.example.com/customer/ would be highlighted during the live log Tail

CodePudding user response:

Converting my comment to answer so that solution is easy to find for future visitors.

You may use this command:

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

Pattern https://www\.example\.com[^"]* matches a substring starting with https://www.example.com followed by 0 or more non-" characters.

  •  Tags:  
  • Related