Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

how can i get "+45.0°C" if the following output was a file (

I can get it to one line by doing

sensors -A acpitz-virtual-0 > sen
grep temp1 ~/sen

but it still has a load of useless crap on it:

"temp1:        +42.0°C  (crit = +90.0°C)"
share|improve this question
up vote 3 down vote accepted

Here's the answer: For instance these are the texts inside the file

Adapter: Virtual device
temp1:        +45.0°C  (crit = +90.0°C)
temp2:        +45.0°C  (crit = +90.0°C)

To get the +45.0°C of temp1, use this command:

grep temp1 < theFileWithTemp.txt | awk '{print $2}'
share|improve this answer

You may use egrep (or grep -e) to use regular expressions. With .{7} 7 arbitrary characters:

echo -e "temp1:\t+42.0°C  (crit = +90.0°C)" | egrep -o "temp1:.{7}"
temp1:  +42.

With -o you restrict the output to your match. To cut off just the rest of the line:

 echo -e "temp1:\t+42.0°C  (crit = +90.0°C)" | egrep -o "temp1:.{7}" | egrep -o ".{5}$"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.