-3

When I type in uptime in terminal it gives me something like this

 16:44:17 up  7:50,  load average: 0.31, 0.47, 0.54

I want to make it to be something like this

Uptime: 7h 50m
Load average: 0.31, 0.47, 0.54

and save it to uptime.txt

How can I do that? I'm sorry for the dumb question, I'm still new in this and I've googled before but I find nothing useful.

Squidward
  • 131
  • 3
  • 14
  • You’re probably getting downvotes because you showed us no code of your own. [SO] is not a code writing service, it’s a community of programmers. Even as a beginner, you should be able to show us some code so that we know what you know and can fill in the missing bits. It there are too many of those, this question is too broad and it cannot be answered here; the answers would be extremely long. – Palec Dec 20 '14 at 11:12
  • 1
    I didn't know that, I registered just yesterday. I'll try to come up with my own codes next time, thank you for the heads up. – Squidward Dec 20 '14 at 11:14

2 Answers2

1

You can use awk with uptime:

uptime | awk -F ' up | load average:' '{sub(/,.*$/, "", $2); 
             printf "Uptime: %s\nLoad average: %s\n", $2, $NF}'
Uptime: 23 days 16:14
Load average:  2.19, 1.91, 1.88
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

this ugly command will work:

uptime | sed 's#[0-9][0-9]:[0-9][0-9]:[0-9][0-9]##g' | sed 's#:#h #g' | sed -E 's#, [^,]+users,#m#g' | sed 's/ days,/d/g'|sed 's/  up/Uptime:/g' | sed 's/load averageh/\nLoad average:/g'
armnotstrong
  • 8,605
  • 16
  • 65
  • 130
  • it shows `Uptime: 8h 42, Load average: 1.68, 1.65, 1.45` how to add "m" on `42` ? the minute word isn't showing – Squidward Dec 20 '14 at 10:38