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)" 

2 Answers

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}' 

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}$" 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy