News for hackers. Stuff that matters.
Re:Unix Text Processing (1987) by twistedanimator on Tuesday December 11, 2012 @08:45AM (#4904453)
Just yesterday I was able to write a one liner on the command line to analyze my skype usage. I wanted to see if it was making financial sense to keep skype alongside my prepaid wireless plan.

You can download your last six months of skype activity from skype.com and they are in the form:

Date;Date;Item;Destination;Type;Rate;Duration;Amount;Currency "July 31, 2012 21:16";"2012-07-31T21:16:01+00:00";"+11234567890";"USA";"Call";0.000;00:00:10;0.000;USD "July 31, 2012 21:15";"2012-07-31T21:15:38+00:00";"+11234567890";"USA";"Call";0.000;01:17:02;0.000;USD

After 15 minutes or so, I came up with the following one liner:

cut -f7 -d";" call_history* | grep -v "Duration" | awk '{ FS=":"; s+=$1*60; s+=$2; if ($3 != 00) { s+=1 } } END {print s " minutes"}'

I could have done the same thing in perl or python in 5 minutes, but it was interesting to "program" only by hooking programs together to achieve the same thing.

After analyzing my skype logs, I found I used 1800 minutes. That would have cost me $180 with prepaid minutes, but only cost $30 with skype.

Re:Unix Text Processing (1987) by ralph on Tuesday December 11, 2012 @01:33PM (#4905919)
Another way would be all awk.

    awk -F\; '
        $7 != "Duration" {
            split($7, t, ":")
            s += t[1] * 60 + t[2] + (t[3] != 0)
        }
        END {print s + 0}
    '
Note the handling of s == "" in END.
Re:Unix Text Processing (1987) by ralph on Tuesday December 11, 2012 @01:52PM (#4906062)
The sed and dc combo are perhaps not as readable, but there was a time before the dawn of the One True Awk. :-)

    sed '1s/.*/0/; s/;[^;]*$//; s///; s/.*;//
        s/00$//; s/:..$/+1++/; s/:$/++/; s/:/ 60*/; $s/$/p/' |
    dc