-1

When uptime normally prints out like this

ubuntu@ubuntu:~$ uptime -p
up 4 days, 1 hour, 43 minutes

How could I get it to print out in a shorter format, something like:

up 4d, 1h, 43m

I need to keep it short to display it on a 1602 lcd screen. I would also prefer a oneliner but that's not neccessary.

Ledi
  • 51
  • 7
  • Anyway, you can do this with a trivial `sed` command. – Barmar Sep 20 '21 at 21:15
  • 1
    Hint: write a regular expression that captures a number followed by a space and word, and replaces it with the number and the first letter of the word. – Barmar Sep 20 '21 at 21:17

1 Answers1

0

This was way simpler question than I first thought, just replace the words...

uptime -p | sed 's/up\s*//g' | sed 's/\s*days/d/g' | sed 's/\s*hours/h/g' | sed 's/\s*minutes/m/g'

produces:

4d, 2h, 12m
Ledi
  • 51
  • 7
  • You only need one `sed` and no `/g`s: `uptime -p | sed 's/up\s*//; s/\s*days/d/; s/\s*hours/h/; s/\s*minutes/m/'` – wjandrea Sep 20 '21 at 21:55