Hard to explain if we do not know input data.
Anyway - 'grep ^Cpu' should work. Empty output file tells only that there are no lines with word "Cpu" on the beggining of a line.
Yes, I got them.
I don't want to get data first then using grep, because it make output file become a huge file. I want to run top -b for one or two days, that's the issue.
If you run it without redirection, do you see the results on your screen?
If you terminate it with ctrl-c, the output might still be buffered somewhere (weak hunch, might be wrong) -- if you let it run for long enough, does the output become visible?
Tested here; looks like I'm right. If I hit ctrl-c after five seconds (enough to produce about two matching lines, I guess) the output file is empty. If I run it for a minute or so, I still don't get output in the file. Then all of a sudden, lots of output. It's output buffering at play.
If you have grep --line-buffered, try with that, just to see that it works. If you run it for long enough, you probably want to take it out again, though.
@era: Yes, I can see the result on the screen without redirection.
I left it run for half a day (without grep), and kill it, I got the output with over 200MB
The problem is that grep does not write the result immediately. If you quit it before the first result has been written, the output file will still be empty. Run it without caching if you have a grep which has that option, or just live with the fact that the last buffer (probably something like 4k to 8k) might be lost when you quit it.
Did you miss comment #10 or did you not understand it?