I want to extract the maximum temperature value from the output of a command, which I store in a shell variable as follows:
res="$(get temperature all)"
where the result looks like
Device 0 avs data: Temperature: 33.5 C voltage1V0: 0.926 V voltage1V8: 1.782 V voltage3V3: 3.265 V Device 1 avs data: Temperature: 32.6 C voltage1V0: 0.923 V voltage1V8: 1.780 V voltage3V3: 3.265 V Device 2 avs data: Temperature: 33.1 C voltage1V0: 0.920 V voltage1V8: 1.785 V voltage3V3: 3.290 V Device 3 avs data: Temperature: 33.1 C voltage1V0: 0.921 V voltage1V8: 1.780 V voltage3V3: 3.265 V
I want to extract the numerical value enclosed between the strings
C, and find the maximum value from all the device records. For the above case, the output should be
since the temperature values are 33.5, 32.6, 33.1, 33.1
In the above command, the output gives
- sometimes only
so finding max temperature logic should be generic irrespective of devices count (though the max count is 4, min count is 1 for available devices).
So for example, if only a single device is present then the max temperature should be equal to device 0 temperature, otherwise we need to compare and print.
Edit 1 - I need to use
grep -P option is not available.
echo 'Here is a string, and Here is another string.' | grep -oP '(?<=Here).*(?=string)' grep: invalid option -- 'P'
"echo 'Here is a string, and Here is another string.' | grep -oP '(?<=Here).*(?=string)'grep: invalid option -- 'P'" . So looks like -p is not available on my system. so need to use awk or sed instead.