LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-02-2010, 07:55 AM   #1
Evgeniy Arbatov
LQ Newbie
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 5

Rep: Reputation: 0
Saving awk output to file


Hello,

I have a problem with saving output from awk to a file. The commands I tried:

Code:
$ top | awk '/Cpu|Mem/ {if ($1 ~ /Cpu/) {printf strftime("%H:%M:%S")"\t"; printf strtonum($3)"\t";} if ($1 ~ /Mem/) {printf ($5/$3)*100; printf "\n";}}' > file.out
and

Code:
$ top | awk '/Cpu|Mem/ {if ($1 ~ /Cpu/) {printf strftime("%H:%M:%S")"\t"; printf strtonum($3)"\t";} if ($1 ~ /Mem/) {printf ($5/$3)*100; printf "\n";}}' &> file.out
In both cases file.out is empty. What am I doing wrong? Thanks!

Evgeniy
 
Old 02-02-2010, 08:06 AM   #2
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 1,924

Rep: Reputation: 278Reputation: 278Reputation: 278
Programs that update the console display usually won't work with redirects.
 
Old 02-02-2010, 08:12 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Use the -b (batch mode) flag for top. Have a look at the man page.

Cheers,

Evo2.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk or sed to use CSV as input and XML as template and output to a single file bridrod Linux - Newbie 6 03-13-2012 08:00 PM
saving xterm output to file khdani Linux - Newbie 1 10-23-2009 06:39 PM
saving output from FIFO? slimshady Linux - Newbie 0 11-29-2007 12:18 PM
Awk Output kalyanofb Programming 4 02-02-2007 03:23 AM
Saving the output of a file as a variable mrobertson Programming 5 07-08-2005 01:43 AM


All times are GMT -5. The time now is 04:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration