PDA

View Full Version : Who can shorten this command?



Legendary_Bibo
June 2nd, 2011, 02:05 PM
I was bored because I couldn't fall asleep (still can't actually) so I bugged around with the sensors command, and I just wanted it to print out the the temperature from the virtual device, not the PCI sensor, and nothing more (it's more accurate).


sensors -A > sensorinfo3 && cat sensorinfo3 | cut -f2 -d'+' > sensorinfo4 && sed -n 2p sensorinfo4 > sensorinfo5 && cat sensorinfo5 | cut -c1-7

I then made is into a shell script and wrote an alias in my bashrc file so that 'sensors' would redirect to this script instead.

VCoolio
June 2nd, 2011, 04:31 PM
Maybe post the output of "sensors -A" and indicate what part you want. You can do something like this (replace "string" with a string that is unique to the line your info is in, and replace "3" with the right number to get your value:
sensors -A | awk '/string/ { print $3 }'

amauk
June 2nd, 2011, 04:45 PM
sensors -A > sensorinfo3 && cat sensorinfo3 | cut -f2 -d'+' > sensorinfo4 && sed -n 2p sensorinfo4 > sensorinfo5 && cat sensorinfo5 | cut -c1-7Just a note
You're using a lot of unnecessary temporary files in the above

If you rewrite it to use pipes instead, it'll be shorter, more efficient, and you won't have lots of temporary files lying around

sensors -A | cut -f2 -d'+' | sed -n 2p | cut -c1-7

(Efficiency is probably not noticeable on this script, but on anything more substantial, it'll be noticeably quicker)