Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

All,
I'm using

top -l 0 -s 1  -pid XXX -stats rsize | awk 'NR%13==0; fflush(stdout)' > output.txt  

to store the rsize value of a process in a file. Currently the contents of output.txt look like this:

3828K+   
3832K+  
3836K+  
3840K+  
3840K   
3840K   

I would like to modify this one-liner to include timestamp along with the value. How do I modify the awk part of the above one-liner and add timestamp to it? The resultant output should look like this:

1338936728 3828K+  
1338936729 3838K

I'm on a Mac OSX. I would like to make a timestamp Vs rsize plot.

share|improve this question
    
Can you include a complete output line? I don't have an OSX machine, and my version of top doesn't take the same flags –  Michael Mrozek Jun 5 '12 at 23:02
    
@MichaelMrozek: What do you mean by "complete output line"? I'm essentially running the top command in batch mode in the above one-liner –  smokinguns Jun 5 '12 at 23:05
    
A line unprocessed by awk. I assume "timestamp" is one of the other columns –  Michael Mrozek Jun 5 '12 at 23:16
    
@MichaelMrozek: There is no timestamp column in the top command output. I thought of modifying the awk part of the one-liner to add a timestamp –  smokinguns Jun 5 '12 at 23:28
    
I am on a mac and that's not giving me anything remotely like your output. –  Kevin Jun 6 '12 at 1:30
add comment

1 Answer 1

It depends on your awk version (you probably have to use gawk instead of awk) or directly run date in your awk commandline, but

awk 'NR%13==0 { printf  "%d %s\n",  systime(), $0 ; fflush(stdout) }'

will print the current timestamp in front of the current line. For more information have a look at the gawk documentation about time functions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.