Data exploration with awk
Help 6 / 12
Variables

Auto-initialization of variables

Note that awk automatically initializes variables for you, so sum = 0 is not strictly necessary (but preferable for clarity):

awk -F "\t" ' \
   { if($3 == "Chicken Bowl") sum += $2 } \
   END { print(sum) }' orders.tsv

As a side note, awk doesn’t actually need a file to work on if you only provide it with a BEGIN statement and no body:

awk 'BEGIN{ print(5/7) }'

(that’s one easy way to do floating-point math on the command line, as Bash itself only supports integers).

Loading...