I'd like to trim the output from uptime
20:10 up 23 days, 3:28, 3 users, load averages: 3.84 1.06 0.64
so that it just shows:
23 days
I've tried using sed, but I'm not sure it's the right tool for the job, and don't have much experience using it.
How can I achieve the output I want?
Consider using cut
.
uptime | tr "," " " | cut -f6-8 -d" "
seems to work on my MacBook. Here I've also used tr
to kill an extraneous ",". There is a bit of an issue with different formats for short and long uptimes.
A possible sed solution:
uptime | sed 's/.*up \([^,]*\), .*/\1/'
which doesn't rely on the string "days" appearing in the output of uptime
.
uptime | sed -E 's/^.+([0-9]+ days).+$/\1/'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With