AWK Restrictive Search

I have a file with most of the lines formatted in this way:

testaccount:D#%G%^V&:MeMyselfandI:memyselfandi@somesite.com:11/242012:192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5

There are a few lines with:

testaccount2:D#%G%^V&:MeMyselfandI:memyselfandi@somesite.com:11/242012:192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5:reminder2012 $56.00

and 
testaccount2:D#%G%^V&:MeMyselfandI:memyselfandi@somesite.com:11/242012:192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5:$56.00

using AWK I have a one-liner that excludes case sensitivity, uses the field delimeter ":" and searches for the account name and if there is any ip adress/ip adresses associated with the string:

cat wspasswd| awk -F ':' 'tolower($1) ~ /^testaccount2/ && /[0-9][0-9][0-9][0-9]/'

which print the whole sting correctly:

testaccount2:D#%G%^V&:MeMyselfandI:memyselfandi@somesite.com:11/242012:192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5:$56.00

That is fine but my question is, how can I have awk additionally, once it finds the account name and the ip adress/ip adresses to print out "only the ip adress/ip adresses"

using testaccount2 as an example

cat wspasswd| awk -F ':' 'tolower($1) ~ /^testaccount2/ && /[0-9][0-9][0-9][0-9]/ {print $(NF-1)}'
192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5

The above worked because the ip addess/ip address reside in the next to last field but what do I do if the field is in the last field. Is there a way I can tell AWK once it finds the account name and the ip adress/ip adresses to print out "only the ip adress/ip adresses" no matter where they are in the sting

awk -F: 'tolower($1) ~ /testaccount2/{for(i=1;i<=NF;i++){if($i ~ /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/) print $i}}' inputfile
2 Likes

Thank you for you reply but it did not work.

cat wspasswd | awk -F: 'tolower($1) ~ /^testaccount2/{for(i=1;i<=NF;i++){if($i ~ /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/) print $i}}'

it prints nothing.

---------- Post updated at 05:16 PM ---------- Previous update was at 04:35 PM ----------

awk -F ':' 'tolower($1) ~ /^testaccount2/ { for ( i = 1; i <= NF; i++ ) { if ( $i ~ /[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ ) print $i } }' wspasswd

This did many many thanks.