1

This command nstats gives me output like below. How can I use awk or grep to give me the uptime with only days on it? I cannot use the "" to get the output.

HOSTNAME  LOAD  MEMORY  SWAP  PROCS  TIME  UPTIME
Server    0.01     9%     3%    54  10:39  22 days 10:16:03

1 Answer 1

3

With grep - egrep -o "[0-9]+ days"

(your nstats command) | sed -n '2p' | egrep -o "[0-9]+ days"
22 days

With awk - awk '{print $14,$15}'

(your nstats command) | sed -n '2p' | awk '{print $7,$8}'
22 days

With awk (just the days) - awk '{print $14}'

(your nstats command) | sed -n '2p' | awk '{print $7}'
22
5
  • The OP's nstats output was actually two lines of text, not one.
    – Kenster
    Sep 18, 2014 at 16:00
  • What do you mean two lines? I see just one line.
    – unlink
    Sep 18, 2014 at 16:04
  • It's two lines in the markdown for the question (the actual text entered by the user), but it was being line-wrapped. The question has been edited to format the text correctly.
    – Kenster
    Sep 18, 2014 at 16:10
  • Yes, I see it now.. I edited my response accordingly.
    – unlink
    Sep 18, 2014 at 16:53
  • That egrep answer is a nice one, here... I didn't know about -o; very useful!
    – lindes-hw
    Sep 19, 2014 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.