Tag Info

New answers tagged

0

Another perl: $ w | head -1 | perl -nle 'print +(split /load average:/)[-1]' 0.42, 0.49, 0.63


5

You can also use awk: $ w | head -1 | awk '{print $10,$11,$12}' 0.80, 0.84, 0.93 Or, if the number of fields is variable, use: $ w | head -1 | awk '{print $(NF-2),$(NF-1),$NF}' 0.81, 0.82, 0.91 Or, the much more elegant (thanks @Letitzia): $ w | head -1 | awk -F "load average: " '{print $2}' Sed: $ w | head -1 | sed 's/.*load average: *//' Perl: ...


3

Normally I'd just use the ${parameter#word} bash parameter expansion. It expands $parameter, deleting word (which can be a pattern) from the start. In your case, something like: line=... echo ${line#*load average: } Making it a function: get_load() { w | head -n 1 | { read -r line; echo ${line#*load average: }; } }


3

If you want only last numbers you can use grep: $ w | grep -Po 'load average: \K.*' 0.07, 0.13, 0.09



Top 50 recent answers are included