brasay
brasay

Reputation: 135

change variable output in bash

I have a bash script that contains the following text:

LOAD=`/usr/bin/w |grep "load average"`
echo $LOAD 

when I execute the script it searches for load average in the files inthe directory that is given. After it's executed the output is the following:

10:06:40 up 7 days, 17:21, 3 users, load average: 0.08, 0.06, 0.09

What I want is the $LOAD variable to give the following output:

10:06:40 up 7 days, 17:21, 3 users, load averages: 0.08, 0.06, 0.09

I can't recompile the files in the directory that is given so that is not an option. Any ideas how I am able to achieve this output?

Thanks in advance

Upvotes: 0

Views: 70

Answers (2)

Adrian Frühwirth
Adrian Frühwirth

Reputation: 45706

See parameter expansion. This replaces the first occurance of average with averages:

echo "${LOAD/average/averages}"

Upvotes: 1

Josh Jolly
Josh Jolly

Reputation: 11796

So you just want to change "average" to "averages"?

echo "$LOAD" | sed 's/average/averages/'

Upvotes: 4

Related Questions