Somanath Patil Somanath Patil - 6 months ago 52
Linux Question

regular expression to extract only Customerid and Data (bytes) and save in list?

I have the below logs

01-01-2012 01:13:36 Blah blah : blah CustomerId:1234 downloaded Blah Size:5432 bytes Carrier:Company-A
01-01-2012 01:13:36 Blah blah : blah CustomerId:1237 downloaded Blah Size:5432 bytes Carrier:Company-B

Can somebody tell me a regular expression to extract Customer id and Size and save in list and print how much data downloaded by each customer id? I was able to do this using search and Dictionaries in Python. request you guys to provide using regular expressions.

my %total_downloaded_by_id;
while (<>) {
   my ($id, $size) = /CustomerId:(\S+).*Size:(\S+)/
      or next;

   $total_downloaded_by_id{$id} += $size;