# Pastebin EjXQ78yK # This awk program BEGIN { FS = " *= *"; in_section = 0 } /^\[.*\]/ { in_section = 0 } /^\[aws_profile\]/ { in_section = 1 } /^aws_access_key_id/ && in_section { print $2 } # Against this input [no] aws_access_key_id = wrong key [aws_profile] aws_access_key_id = right key [also no] aws_access_key_id = wrong key # Prints right key