awk ' $2 ~ /localhost/ { print $0 } ' /etc/hosts [download]
Originally posted as a Categorized Question.
In reply to What is the simplest way to print a field, as in $3 does in awk by Anonymous Monk