diff --git a/sheets/awk b/sheets/awk index fc64bb5..a68bca2 100644 --- a/sheets/awk +++ b/sheets/awk @@ -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)