Read time: 1 minute

In the battery-alert script, I needed to get the information about the charging status of the system. I found ‘acpi’ command that displays information like:

Battery 0: Charging, 75%, 00:31:46 until charged

and

Battery 0: Discharging, 74%, 02:37:34 remaining

So I got what I needed i.e. the keywords Charging and Discharging. So I pick up and piped the above output to awk. Awk is a programming language used for files, pattern scanning, processing and more. More specifically, I tried:

acpi -b | awk '{print $3}'

But it gives output as “Charging,” and “Discharging,”. So I decided to use the cut command as:

acpi -b | awk '{print $3}' | cut -c9 --complement

It returned “Charging” by removing the comma. But wait, when I tried while pulling out the charger, then the result was: Dischargng,

So found a better way. What it does is that it first reverses the string and then removes the first character and then reverses it back again. So this does the purpose.

acpi -b | awk '{print $3}'| rev | cut -c 2- | rev

I just had a thought to replace the upower command with the acpi.