diff --git a/sheets/awk b/sheets/awk index 96b5f26..b6b3e6c 100644 --- a/sheets/awk +++ b/sheets/awk @@ -1,7 +1,7 @@ -# sum integers from a file or stdin, one integer per line: +# sum integers from a file or STDIN, one integer per line: printf '1\n2\n3\n' | awk '{ sum += $1} END {print sum}' -# using specific character as separator to sum integers from a file or stdin +# using specific character as separator to sum integers from a file or STDIN printf '1:2:3' | awk -F ":" '{print $1+$2+$3}' # print a multiplication table @@ -16,30 +16,30 @@ awk -v RS='' '/42B/' file # display only first column from multi-column text echo "first-column second-column third-column" | awk '{print $1}' -# Use awk solo; without the need for something via STDIN. +# Use AWK solo; without the need for something via STDIN. awk BEGIN'{printf("Example text.\n")}' -# Accessing environment variables from within awk. +# Accessing environment variables from within AWK. awk 'BEGIN{print ENVIRON["LS_COLORS"]}' # One method to count the number of lines; in this case, read from STDIN. free | awk '{i++} END{print i}' -# Output a (unique) list of available sections under which to create a DEB package. +# Output 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. +# 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. +# 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. awk '/^Mem:/{print($2)}' <(free -h) -# Output a unique-d list of uppercase-only, sigil-omitted variables used in [FILE]. +# Output list of unique uppercase-only, sigil-omitted variables used in [FILE]. awk '{for(F=0; F