Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm working on some SPAM graphing with mrtg and gnuplot, and have run into a bit of a conversion I'd like to try to migrate to perl. Basically I have the following:
grep ^"From " SPAM-mbox | \ awk '{$1 = $2 = $6 = ""; \ gsub(/-0[45]00/, ""); \ gsub(" ", "-"); \ print $0}' | \ sort | \ sed s/-$//g | \ uniq -c > spamstatfile

This returns the following:

1 --Fri-Jun-13--2003 1 --Fri-Jun-20--2003 2 --Mon-Jun-9--2003 10 --Tue-Jun-24--2003 3 --Wed-Jun-11--2003 1 --Wed-Jun-18--2003

What I'm trying to do, is swap the first and second columns, but I can't figure out how to easily do that (either with awk's backtracking, or with this converted into a perl one-liner). Once I can do this (without manually swapping the columns), I'll be shoving it into gnuplot with:

set xdata time set timefmt "%b-%d-%Y" plot "spamstatfile" using 1:2

Any ideas on how I can swap those columns either with perl or awk? Or perhaps a better way to do this entirely in perl?

jmacnamara's suggestion got me 99.99% of the way there. Here's a slightly-modified version which now works:

perl -lane '$h{"$F[3]-$F[4]-$F[6]"}++ if /^From /; END { print $_, "\t", $h{$_} for keys %h }' SPAM > spamdates

And then I just run gnuplot -persist spam.gnuplot across my control file. Done.

Now to fancy it up a bit and add more heuristics.

In reply to Perlify some awk'ing for SPAM graphing by hacker

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2018-05-27 02:01 GMT
    Find Nodes?
      Voting Booth?