Hi everyone,

I’m looking to clean up the output of a few scripts triggered by APCUPSD.

For example:
The output of:

/sbin/apcaccess status | grep STATUS

/sbin/apcaccess status | grep LINEV

is

STATUS   : ONLINE

LINEV    : 121.0 Volts

How can I manipulate the script to only print the text beyond the colon. My goal is something like:

UPS Status: $STATUS
Line Voltage: $LINEV
#etc..

I was considering writing a whole statement to pull the data I want, but something tells me I would over complicate the whole thing. :slight_smile:

Thanks in advance.

7 Spice ups

Along with piping the commands to grep, you can also pipe them to awk to display output after a specified space in the output. ex:

/sbin/apcaccess status | grep STATUS | awk ‘{ print $2 }’

/sbin/apcaccess status | grep LINEV | awk ‘{ print $2,$3 }’

I mught have the syntax slightly off, but play around with it, there’s lots of documentation on awk.

6 Spice ups

Excellent!

That is exactly what I was looking for!

Thank you!

Anytime! Awk is pretty awesome. It’s those little things.

or bamh!

/sbin/apcaccess status | grep -P 'STATUS|LINEV' | cut -d: -f2

5 Spice ups

That’s what I would have used. ^^

Easier syntax, but awk is more powerful.

1 Spice up