Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  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


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

$ 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

$ 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!

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

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

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




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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:26 AM.

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