Hi everyone,<\/p>\n
I’m looking to clean up the output of a few scripts triggered by APCUPSD.<\/p>\n
For example:
\nThe output of:<\/p>\n
/sbin/apcaccess status | grep STATUS\n\n/sbin/apcaccess status | grep LINEV\n\n<\/code><\/pre>\nis<\/p>\n
STATUS : ONLINE\n\nLINEV : 121.0 Volts\n\n<\/code><\/pre>\nHow can I manipulate the script to only print the text beyond the colon. My goal is something like:<\/p>\n
UPS Status: $STATUS\nLine Voltage: $LINEV\n#etc..\n<\/code><\/pre>\nI was considering writing a whole statement to pull the data I want, but something tells me I would over complicate the whole thing.
<\/p>\n
Thanks in advance.<\/p>","upvoteCount":7,"answerCount":6,"datePublished":"2014-12-04T16:48:41.000Z","author":{"@type":"Person","name":"jamesposs0582","url":"https://community.spiceworks.com/u/jamesposs0582"},"acceptedAnswer":{"@type":"Answer","text":"
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:<\/p>\n
/sbin/apcaccess status | grep STATUS | awk ‘{ print $2 }’<\/p>\n
/sbin/apcaccess status | grep LINEV | awk ‘{ print $2,$3 }’<\/p>\n
I mught have the syntax slightly off, but play around with it, there’s lots of documentation on awk.<\/p>","upvoteCount":6,"datePublished":"2014-12-04T17:23:42.000Z","url":"https://community.spiceworks.com/t/help-with-grep/361772/2","author":{"@type":"Person","name":"claypool","url":"https://community.spiceworks.com/u/claypool"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hi everyone,<\/p>\n
I’m looking to clean up the output of a few scripts triggered by APCUPSD.<\/p>\n
For example:
\nThe output of:<\/p>\n
/sbin/apcaccess status | grep STATUS\n\n/sbin/apcaccess status | grep LINEV\n\n<\/code><\/pre>\nis<\/p>\n
STATUS : ONLINE\n\nLINEV : 121.0 Volts\n\n<\/code><\/pre>\nHow can I manipulate the script to only print the text beyond the colon. My goal is something like:<\/p>\n
UPS Status: $STATUS\nLine Voltage: $LINEV\n#etc..\n<\/code><\/pre>\nI was considering writing a whole statement to pull the data I want, but something tells me I would over complicate the whole thing.
<\/p>\n
Thanks in advance.<\/p>","upvoteCount":7,"datePublished":"2014-12-04T16:48:41.000Z","url":"https://community.spiceworks.com/t/help-with-grep/361772/1","author":{"@type":"Person","name":"jamesposs0582","url":"https://community.spiceworks.com/u/jamesposs0582"}},{"@type":"Answer","text":"
Excellent!<\/p>\n
That is exactly what I was looking for!<\/p>\n
Thank you!<\/p>","upvoteCount":0,"datePublished":"2014-12-04T18:04:56.000Z","url":"https://community.spiceworks.com/t/help-with-grep/361772/3","author":{"@type":"Person","name":"jamesposs0582","url":"https://community.spiceworks.com/u/jamesposs0582"}},{"@type":"Answer","text":"
Anytime! Awk is pretty awesome. It’s those little things.<\/p>","upvoteCount":0,"datePublished":"2014-12-04T18:18:53.000Z","url":"https://community.spiceworks.com/t/help-with-grep/361772/4","author":{"@type":"Person","name":"claypool","url":"https://community.spiceworks.com/u/claypool"}},{"@type":"Answer","text":"
or bamh!<\/p>\n
/sbin/apcaccess status | grep -P 'STATUS|LINEV' | cut -d: -f2\n<\/code><\/pre>\n<\/p>","upvoteCount":5,"datePublished":"2014-12-04T18:33:51.000Z","url":"https://community.spiceworks.com/t/help-with-grep/361772/5","author":{"@type":"Person","name":"itninja5778","url":"https://community.spiceworks.com/u/itninja5778"}},{"@type":"Answer","text":"
That’s what I would have used. ^^<\/p>\n
Easier syntax, but awk is more powerful.<\/p>","upvoteCount":1,"datePublished":"2014-12-04T19:30:44.000Z","url":"https://community.spiceworks.com/t/help-with-grep/361772/6","author":{"@type":"Person","name":"gregmoore2167","url":"https://community.spiceworks.com/u/gregmoore2167"}}]}}