I have a help file1 format:
client1 bla blahblah 2542 KB
client1 bla blahblah 4342 MB
client1 bla blahblah 7 GB
client2 bla blahblah 455 MB
client2 bla blahblah 455 MB
...
And I need to get a weekly
client1 SUM xy KB
client2 SUM yx KB
Currently im is using:
sumfunction ()
{
inputfile=helpfile1
for i in `awk -F":" '{print $1}' $inputfile| sort -u | xargs`
do
awk -v name=$i 'BEGIN {sum=0};
$0~name {
print $0;
if ($5 == "GB") sum = sum + $4*1024*1024;
if ($5 == "MB") sum = sum + $4*1024;
if ($5 == "KB") sum = sum + $4};
END {print name " SUM " sum " kB"}' $inputfile
done
}
sumfunction | grep SUM | sort -g -r -k 3 > weeklysize
I need to use it on a rather long file, and this awk takes too much time. Is there any other code (only bash) to make this faster? thank you
source
share