|
Problem in redirecting awk output into a file
Hello,
I am trying to redirect the CPU Usage and Memory Usage of a process into a file. To do this I am using top command with awk:
top -S -d 1 | awk '/'"gnome-terminal"'/ {print $10,":",$11,";" > "/tmp/test.log";}'
The generated log file contains many junk data along with the following wrong data:
%CPU : %MEM ;
2 : 0.0 ;
2 : 2.1 ;
0.0 : 0:00.02 ;
0.9 : 0:37.80 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
0 : 0.0 ;
But when I am executing the following command:
top -S -d 1 | awk '/'"gnome-terminal"'/ {print $10,":",$11,";";}'
It is giving correct output:
1 : 0.4 ;
1 : 0.4 ;
1 : 0.4 ;
1 : 0.4 ;
1 : 0.4 ;
1 : 0.4 ;
1 : 0.4 ;
3 : 0.4 ;
2 : 0.4 ;
2 : 0.4 ;
Is there any way to fix this problem?
Thanks in advance.
Regards,
Deb
|