Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

how can i get "+45.0°C" if the following output was a file (http://paste.linuxthefish.net/4@raw)?

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
add comment

2 Answers 2

up vote 3 down vote accepted

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

acpitz-virtual-0
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
add comment

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
add comment

Your Answer

 
discard

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.