Extract data from “w”

I was in a job interview a few years ago and was ask do perform a simple task on a linux box. The question was “Extract the 5min load value and display on a single line?”

Easy enough I thought. I could extract the value, but could not display it on single line. I was lost and realized my skill and knowledge was not there. At this stage I had about 5years experience with linux.

After the interview, I thought about it and realized that my work does not allow me to extract information on a daily basis. It was maintaining systems, not retrieving data. I had other programs/utilities that I used for monitoring and not my own.

I went back and started reading again and doing research to increase my knowledge and started writing my own bash scripts and ‘one liners’ to retrieve information in log files.

The point of all this is, we do not know all the ways to retrieve information. In linux there is more then one-way to retrieve information.

This question is one of a few that I will not forget and will carry with me for my working life. It keeps me humble on my skills.

My solution after doing my homework:
w | awk -F "load" '{ print $2 }' | cut -d, -f2 | sed '/ *#/d; /^ *$/d'

I would like to hear about your experience and other ways to do it.


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.