I'm trying to write a nice csv-file based on some output from top. I reformat the output with awk like this:
top -b | nawk '/Cpu/ || /Tasks/ { if($1 ~ /Cpu/) { printf "%s,",$3 } else { printf "\n" } }'
That works perfectly. Now I want to save the output to a file. I would think that using > output.log
should work:
top -b | nawk '/Cpu/ || /Tasks/ { if($1 ~ /Cpu/) { printf "%s,",$3 } else { printf "\n" } }' > output.log
However, this simply results in an empty file when I Ctrl-C out of the top-process. What am I doing wrong?