Thanks for your quick response. Just to clarify the requirement I only want to get the IP address on the line containing 'fred' not 'fred-test..' In addition this script will be run on over 300 servers so that is why I am passing the $HN into the regexp