Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk time sum

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
Hey all (long time), have a file with the following on each line (file is 10,000,000 lines per day):

"7605551212","17045551212","8665551212","context","17045551212","SIP/5060-f5dd3250","","Context","17045551212","2008-10-08 07:46:41","2008-10-08 07:46:41","2008-10-08 07:47:37",56,56,"ANSWERED","DOCUMENTATION"

So I've done the following to parse out what I need:

for i in `cat zero_outcheck`

do

grep $i /var/log/asterisk/cdr-csv/Master.csv |grep 2008-10-07|\
sed '/^"",/d;s/",/"@@/g;s/"//g'|\
awk -F@@ '{printf ("%-30s %-12s %-22s %-22s %-8s \n", $1,$2,$9,$11,$12)}'|\
awk '{printf ("%-22s %-22s %-22s %-22s %-22s %-22s \n", $1,$2,$3,$4,$5,$7)}'

done

Which yields:

7605551212 17045551212 17045551212 2008-10-08 07:46:41 07:47:37

Which is all I care about seeing however I'd like to sum the time: $5, $6 but am stumped about proceeding to have output as:

7605551212 17045551212 17045551212 2008-10-08 07:46:41 07:47:37 56

where 56 is 56 seconds

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 

There may be other solutions, but this works:
Code:
awk '{split($5,b,":");split($6,a,":"); 
for (i=3;i>0;i-=1) {s[i]=a[i]-b[i]; if (s[i]<0) {s[i]+=60; a[i-1]-=1;}}}
END { print s[1]"h "s[2]"m "s[3]"s"}'
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Yes it did but it solely printed out:

0h 0m 0s

I need

Code:
7605551212             17045551212            17045551212            2008-10-08             07:46:41               07:47:37 0h 0m 0s

So I will look and try to chop it in

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 

OK try:
Code:
awk '{split($5,b,":");split($6,a,":"); 
for (i=3;i>0;i-=1) {s[i]=a[i]-b[i]; if (s[i]<0) {s[i]+=60; a[i-1]-=1;}}
print $0" "s[1]"h "s[2]"m "s[3]"s"}'
[noevil]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
;) Thanks so very much

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
I like the tagline by the way... but I miss the significance of some of the numbers in it. 7600 I recognise and of course 31337, but the rest? c5, 40, 2, c,Q, 10410101?

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top