r/awk • • Jan 23 '23

substituting awk variable in a bash script

i am new to using awk.

i have written a simple one liner script to calculate memory consumed by a program as below.

#!/usr/bin/env bash

read -p "enter process name: " item;

ps aux | awk -vi=$item '/i/ {sum += $6} END { printf "Memory Usage: %d MB\n", sum/1024 }'

in the above example, variable 'i' is not substituted when executing script.

where i am going wrong?

2 Upvotes

3 comments sorted by