Advertisement
Bazze

sum_bytes

Sep 26th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.31 KB | None | 0 0
  1. sum_bytes() {
  2.     declare -A sum;
  3.     while read data;
  4.     do
  5.         ip=$(echo $data | awk '{print $1}');
  6.         bytes=$(echo $data | awk '{print $2}');
  7.         if [[ ! ${sum["$ip"]} ]]; then sum[$ip]="0"; fi
  8.         sum["$ip"]=$(expr "${sum["$ip"]}" + $bytes);
  9.     done
  10.    
  11.     for i in "${!sum[@]}"
  12.     do
  13.         echo -e "$i\t${sum[$i]}";
  14.     done
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement