You are not logged in.
Pages: 1
I don't know how to use sed etc. so I thought someone who knows bash scripting can help me. The following is the command I execute and it's output:
$ aticonfig --adapter=0 --od-gettemperature
Adapter 0 - ATI Mobility Radeon HD 4300 Series
Sensor 0: Temperature - 58.50 C
Now I need a script (preferably a one-liner) that will return 58.50 (the temperature) from the above output.
Any help is much appreciated.
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
aticonfig --adapter=0 --od-gettemperature | tail -n1 | gawk '{ printf $5 }'
Offline
Great thank you!
If you don't mind, can you explain how does this work?
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
another way that should work
aticonfig --adapter=0 --od-gettemperature | egrep -o [0-9][0-9]\.[0-9][0-9]
Hofstadter's Law:
It always takes longer than you expect, even when you take into account Hofstadter's Law.
Offline
Don't mean to be awkward, but here's an alternative:
aticonfig --adapter=0 --od-gettemperature | awk '/^ +.*/ {print $5}'
Extra regex vs extra subshell. ymmv.
Edit: I hadn't seen Cyrusm's so my last line probably doesn't make sense.
Last edited by skanky (2010-02-09 21:51:46)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Guys, they are all great and everything, but I still don't understand how any of them actually works. Care to explain?
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
Great thank you!
If you don't mind, can you explain how does this work?
1) pipes via tail which returns the last line, and pipes that through gawk, which prints the 5th field - space separated.
2) Pipes via grep which returns the text anywhere in the output that matches "digitdigit.digitdigit"
3) Pipes via awk which returns the 5th field (space separated) of the line that starts with a space.
There are also other ways of doing it.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Great, thanks!
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
Hey, what about
aticonfig --adapter=0 --od-gettemperature | awk 'END{print $5}'
? No extra regex
Offline
No need to stay away from sed though. Better to learn it eventually:
aticonfig --adapter=0 --od-gettemperature | sed -n -e '/Temperature/s/^.* - //;s/ C.*$//p'
What that says is take the output, don't automatically print the line [-n], then apply the following filter [-e]:
1. find the line with temperature (/Temperature/),
2. Remove everything up until the " - " [s/^.* - //]
3. Remove everything after the " C" [s/ C.*$//]
4. Print the resulting line [p]
Somewhat more painful, but it could be worse. :-)
Offline
Hey, what about
aticonfig --adapter=0 --od-gettemperature | awk 'END{print $5}'
? No extra regex
Nice one. I'd forgotten about that little foible.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Pages: 1