println array in awk code example
Example: bash print keys of awk array
# Example usage for printing keys:
awk '{ a[$1]=$2 } END { for (key in a) { print key } }' input_file
# Where:
# - The above statement prints all keys in the awk array/dictionary
# made from the input_file
# - a[$1] is an array/dictionary in which the first column ($1) is
# used as the key and the second column ($2) is used as the value
# - END indicates what to do after the first statement has finished
# running. Here we start a loop that loops through the keys in the
# array and prints them
# Example usage for printing key values:
awk '{ a[$1]=$2 } END { for (key in a) { print a[key] } }' input_file
# Where:
# - The above statement prints all key values in the awk
# array/dictionary made from the input_file