Add more examples using associate array variables

pull/83/head
terminalforlife 5 years ago
parent 6e507588ec
commit 81711828bc

@ -27,3 +27,11 @@ free | awk '{i++} END{print i}'
# Output a (unique) list of available sections under which to create a DEB package.
awk '!A[$1]++{print($1)}' <<< "$(dpkg-query --show -f='${Section}\n')"
# Using process substitution (`<()` is NOT command substitution), with AWK and its
# associative array variables, we can print just column 2 for lines whose first
# column is equal to what's between the double-quotes.
awk '{NR!=1&&A[$1]=$2} END{print(A["Mem:"])}' <(free -h)
# While below is an easier and simpler solution to the above, it's not at all the
# same, and in other cases, the above is definitely preferable; more accurate.
awk '/^Mem:/{print($2)}' <(free -h)

Loading…
Cancel
Save