0

I have installed tlp in my system to prevent laptop over heating and i used this code to retrieve currtent cpu temperature.

tlp-stat -t 

the output for above command is something like this:

--- TLP 0.7 --------------------------------------------

+++ Temperatures
CPU temp               =    47 [°C]
Fan speed              = (not available)

can you tell me how i can retrieve only the integer part of that output (ie 47). I tried using cut command but i am unable to find an optimum result.

this is the cut command i used

tlp-stat -t | cut -d= -f2 

and the output is

--- TLP 0.7 --------------------------------------------

+++ Temperatures
    49 [°C]
 (not available)

How to refine my cut command to get only the integer two digit value?

2 Answers 2

6

With awk:

... | awk '/CPU temp/ {print $4}'

with grep:

... | grep -oP '^CPU temp.*=.* \K[0-9]+'

with sed:

... | sed -nE 's/^CPU temp.*=.* ([0-9]+).*/\1/p'
3
  • Nice answers, but the question asked how to do it with the cut command.
    – Mike Scott
    Mar 28, 2015 at 12:08
  • 2
    @MikeScott XY Problem.
    – muru
    Mar 28, 2015 at 12:09
  • cut is unfortunately unsuitable.
    – Cyrus
    Mar 28, 2015 at 12:09
4

How about: tlp-stat -t | head -4 | tail -1 |cut -c29-30

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .