To filter sth out, like 'grep -v' { if (($0 !~ "fatal: Not a git") && ($0 !~ "Nokogiri was built") && ($0 !~ "No platform") && ($0 !~ "No Arch") && ($0 !~ "No encoder") && ($0 !~ "succeeded with size") && ($0 !~ /Found [0-9]* compatible encoders/) && ($0 !~ "Attempting to read payload from STDIN")) { print $0 } } Use cases exit bash script from awk server=$( dig $domain mx | awk "/^$domain/{sub(/\.$/, \"\", \$6); print \$6} /connection timed out/{exit 1}" ) if [[ ${?} == 1 ]]; then echo "DNS connection timed out" exit fi