Pulling Ip's from log and redirecting to a file

Hi all,

I am fairly new to scripting, but I do try and script as much as possible but the more advanced stuff does tend to boggle my mind a bit.
I am at a bit of a loss with this one.

I get entries in my DNS logs, like the below:

I want to extract only the IP address, without the hashes or port numbers after it, and output the IP addresses to a file.

I started with a for loop that looks like so:

for x in $(tail -f /var/log/messages | awk '{print $7}') ; do sed -e "s/#*/ /g" $x >> /temp.txt ; done

I am not too sure if sed or awk is the right commands to use here and if there might be an easier way to do this.

Thanks

With GNU grep:

grep -Po '(\d+\.){3}\d+' infile

Or use Perl:

perl -nle'print $1 if /((?:\d+\.){3}\d+)/' infile

It works 100% fine.

Really great thanks.

awk -F'[ #]' '{$0=$7}1' infile

Another one with awk:

awk -F"[ #]" '{print $7}' file

Or:

awk -F'client |#' '$0=$2' infile