How to use the awk to print the output

1

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

asngvas

Posted 2014-09-18T15:43:25.727

Reputation: 11

Answers

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

unlink

Posted 2014-09-18T15:43:25.727

Reputation: 241

The OP's nstats output was actually two lines of text, not one. – Kenster – 2014-09-18T16:00:28.210

What do you mean two lines? I see just one line. – unlink – 2014-09-18T16:04:47.027

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 – 2014-09-18T16:10:28.883

Yes, I see it now.. I edited my response accordingly. – unlink – 2014-09-18T16:53:31.997

That egrep answer is a nice one, here... I didn't know about -o; very useful! – lindes-hw – 2014-09-19T01:07:43.303