I have a file containing only two lines, with the following structure:
$ cat /tmp/pwpower.log
000D6F0000D34227, -114.10
000D6F0001A405C4, -130.09
The values are power values of my solar plant. Negative value means generation.
I would need the values extracted via grep/sed/awk – whatever is the smartest way. I need to have both values extracted separately and without the minus sign.
What I do now is kind of stupid but it works – I'm sure many of you will have smarter ways for me 🙂 Here of course I only see the values plus Minus.
To get the first value:
cat /tmp/pwpower.log |grep -o "\-.*" | head -n 1
To get the second value:
cat /tmp/pwpower.log |grep -o "\-.*" | tail -n1
And related question, is there a simple way to take these STRINGs and transform so that I can calculate the SUM ?
Best Answer
All values:
Value on first line:
Value on second line:
Sum of all values: