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:
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:
But it gives output as “Charging,” and “Discharging,“. So I decided to use the cut command as:
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.
I just had a thought to replace the upower command with the acpi.