views:

20

answers:

1
+1  Q: 

vmstat and column

I want to use column utility to format output of iostat in aligned columns.

I want to run something like:

vmstat 1 10 | column -t

But the output appers only after 10 sec (vmstat completes its work) and not each second.

Any ideas?

+1  A: 

The reason this happens is that column waits to gather as much input as possible on which to base its column guesses. It has no way of knowing that the data pattern repeats every second.

You can approximate what you want to do by running this:

for i in 0 1 2 3 4 5 6 7 8 9; do iostat | column -t; sleep 1; done

EDIT

Thanks to a couple of suggestions from Dennis:

for i in {0..9} ; do iostat 1 1 | column -t; sleep 1; done

The only difference from the original is that the first header line is repeated every second. Some footwork with sed or grep could take care of that.

Carl Smotricz
For vmstat using your proposal you can run: "vmstat | sed -n '1,2p' | column -t; for i in 0 1 2 3 4 5 6 7 8 9; do vmstat | column -t | sed -n '3p';sleep 1; done" which gives similar, but formatted output to "vmstat 1 10". Is there really no way to do it in easy way?
dimba
@idimba: in Bash, you can do `for i in {0..9}`. You can do `vmstat 1 1` in both places.
Dennis Williamson
@idimba: Sorry, I'm not familiar with the vmstat format so I wasn't aware how you wanted the headers to look. I think Dennis' suggestion makes it pretty simple. I'll edit my answer to reflect our best efforts combined.
Carl Smotricz
And no, there doesn't seem to be a way of getting `column` to work differently. I think it's simple enough, don't you? Best I can do, in any case. You might try asking the question on superuser.com, they do more of this kinda stuff.
Carl Smotricz