I am trying to replace an IP address in a dnsmasq logfile with its hostname. The logfile is being 'watched' with the command 'tail -f /var/log/dnsmasq.log' on the console and I want to pipe the output into sed to replace the IP address with the hostname on ONLY the lines that contain the text 'query'. The IP address is always at the end of these lines.
An example line is:
Apr 1 00:47:43 dnsmasq: query[A] gs-loc.apple.com from 10.1.1.188
I believe the command would be in the form of:
tail -f /var/log/dnsmasq.log | sed -e "s/'regex'/$(dig +short -x $1)/g"
The 'regex' needs to identify the lines containing the string "query", extract the IP address from the end of that line and store it (somehow) in a variable - I used the notation
$1 here - that is used in the replace expression with dig.
UPDATE: I omitted to mention that the IP address will always be in the form 10.1.n.n