Skip to content

Instantly share code, notes, and snippets.

@netrunn3r
Last active December 3, 2017 01:53
Show Gist options
  • Save netrunn3r/e19ceea378a8f36936fc7e06eeeacdf3 to your computer and use it in GitHub Desktop.
Save netrunn3r/e19ceea378a8f36936fc7e06eeeacdf3 to your computer and use it in GitHub Desktop.
AWK cheatsheet

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment