LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 06: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, 07:06 AM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Programs that update the console display usually won't work with redirects.
 
Old 02-02-2010, 07:12 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

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

Cheers,

Evo2.
 
  


Reply



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 07:00 PM
saving xterm output to file khdani Linux - Newbie 1 10-23-2009 05:39 PM
saving output from FIFO? slimshady Linux - Newbie 0 11-29-2007 11:18 AM
Awk Output kalyanofb Programming 4 02-02-2007 02:23 AM
Saving the output of a file as a variable mrobertson Programming 5 07-08-2005 12:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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