|
|
Add timestamps to Unix commands that run at intervals
None of the above awk or sed worked right for me (in 10.5), and as for gawk, idunno... but sharing a script and telling users to install gawk is impractical and unnecessary. Regular old awk works fine for this:
...or, add formatting all around for better spacing:
-HI-
Add timestamps to Unix commands that run at intervals
Getting back to a pure Perl solution, and I certainly don't want to get into a Perl golf match with Randal, but the whole substr approach is very specific to the formatting of vm_stat output, and as the OP pointed out, this changes between releases.
It can be accomplished more generally using the default autosplitting on whitespace:
Additional columns can be added by simply specifying more indices to the @F array, i.e., As in Hal's example, additional formatting can be added if desired:
This solution has the advantage over the awk (though not gawk) methods by not having to shell out to get the `date`
Add timestamps to Unix commands that run at intervals
Interesting, it previewed/looked fine under Firefox, but I see your issue under Safari. Lets hope this fixes it.
My apologies.
Add timestamps to Unix commands that run at intervals
(NOTE: this message probably appears in "code" due to a missing code tag in the previous post by slvrstn ?!)Rats!!!... in a flurry of copy/paste editing from Terminal, i accidently posted an older version for the second example. (i.e., no need for the x= variable assignment... that part of example 2 should look just like example 1). I.e., Edited on Jan 22, '10 11:25:07PM by Hal Itosis
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.18 seconds |
|