LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 10-06-2012, 11:53 AM   #1
paldebojyoti
Member
 
Registered: Aug 2009
Posts: 32

Rep: Reputation: 15
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
 
Old 10-06-2012, 05:34 PM   #2
nugat
Member
 
Registered: Sep 2012
Posts: 122

Rep: Reputation: 31
maybe try putting your redirection to file after the closing awk curly brace, e.g.:
Code:
top -n1 -S -d 1 | awk '/gnome-terminal/ {print $10,":",$11,";"}' > /tmp/test.log
 
1 members found this post helpful.
Old 10-06-2012, 06:19 PM   #3
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,619
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by nugat View Post
Code:
top -n1 -S -d 1 | awk '/gnome-terminal/ {print $10,":",$11,";"}' > /tmp/test.log
Good eye!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
redirecting input from file in awk script Trd300 Linux - Newbie 51 09-27-2012 06:57 PM
Redirecting one output to another file amjadask Linux - Server 3 02-14-2011 12:21 PM
redirecting make output to file babu198649 Linux - Newbie 20 09-02-2010 04:30 AM
awk: how can I print out a message to the screen when redirecting the output to file. quanba Programming 5 03-28-2010 06:25 PM
Redirecting output to a compressed file rrosnowski Linux - Software 3 06-13-2007 08:51 AM


All times are GMT -5. The time now is 08:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration