Sunday, April 10, 2011

[Linux Ubuntu] Getting Exact Value of Voltage and Current

We are now one step closer to measuring power process. In the previous explanation, we have got voltage and current value but it still has some obstacles. I mean, there are string "present voltage:" and "present rate" in voltage and current value, respectively. How can we remove them? We employ grep to get certain line and we can use awk get certain column of one line output.
cat /proc/acpi/battery/C1AC/state | grep "present voltage" |
awk '{print $3}'

cat /proc/acpi/battery/C1AC/state | grep "present rate" |
awk '{print $3}'
$3 in awk means it only prints the third column. The value of first column is string "present" and the second one is "voltage" or "rate" in current value. This command will print the exact value only without obstacles. Enjoy!

No comments: