LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Saving awk output to file (https://www.linuxquestions.org/questions/linux-newbie-8/saving-awk-output-to-file-786413/)

Evgeniy Arbatov 02-02-2010 06:55 AM

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

AwesomeMachine 02-02-2010 07:06 AM

Programs that update the console display usually won't work with redirects.

evo2 02-02-2010 07:12 AM

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

Cheers,

Evo2.


All times are GMT -5. The time now is 12:44 PM.