editing uptime output with sed?

Joshua Oreman oremanj at webserver.get-linux.org
Sat May 24 11:14:13 PDT 2003


On Sat, May 24, 2003 at 01:52:11PM -0400 or thereabouts, lbland seemed to write:
> hi-
> 
> sorry for the generic question...
> 
> how do I take uptime output:
>  1:45PM  up 6 days,  3:58, 11 users, load averages: 0.30, 0.24, 0.21
> and get the 2nd to last value with sed? (how do I get sed to output 
> 0.24 to stdout)?

Uptime's output is one of the hardest things for a program/script to
parse. Here's a load average command (for 5 mins; replace the \2 with
\1 for 1 min. or \3 for 15 mins):

uptime | sed -e 's/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\2/' -e 's/ //g'

And an uptime one:

uptime | sed -e 's/.* \(.* days,\)\? \(.*:..,\) .*/\1 \2/' -e's/,//g' -e 's/ days/d/' -e 's/ up //'

HTH,
-- Josh

PS: I didn't test these, I just found them on the Net.

> 
> TIA-
> 
> -lance
> 
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"


More information about the freebsd-questions mailing list