I have the following data that my grep command gives:
$ grep match data.txt
match key1 value1
match key2 value2
match key3 value3
I’d like to have an associative array that is the equivalent of: declare -A animals=( ["key1"]="value1" ["key2"]="value2" ["key3"]="value3")
.
I managed to extract the key and value using awk e.g:
$ grep match data.txt | awk '{print $2}'
key1
key2
key3
I tried to populate the associative array, but I don’t know what the syntax is:
$ declare -A map
$ grep match data.txt | map[$(awk '{print $2}')]=$(awk '{print $3}') # doesn't work