Skip to main content
edited tags
Link
Kahn
  • 1.8k
  • 2
  • 23
  • 41
Source Link
Kahn
  • 1.8k
  • 2
  • 23
  • 41

Multiply element of bash array and set array element to the new value

In bash, if an element in an array is found to contain a K, I want to multiply that element by 1000 and set that element to the product.

for i in "${stats_array[@]}"
do
        if echo "$i" | grep -q K; then
                # set that value to that value times 1000
        fi
done

How is this accomplished in a bash script?

My array might look like:

stats_array: 1, 54, 54K, 99

And I want it to look like:

stats_array: 1, 54, 54000, 99