Add the values of the lines according to a condition

shell scripts

Thread Tools Search this Thread
# 1  
Old 04-20-2018
Add the values of the lines according to a condition

hi everybody Smilie
I am a beginner in bash and I want to convert the result I have here
I want it to be grouped by IP address
so iwanna get for each ip adsress the addition of all bandwidth where ip is
in other words for it groups me all the values whose ip address is
is it possible?
4,03446 MB     -->
3,78212 MB     -->
1,42352 MB     -->
0,181173 MB    -->
0,0822248 MB   -->
0,0522203 MB   -->
0,0475864 MB   -->
0,0471096 MB   -->
0,0458832 MB   -->
0,0346823 MB   -->
0,0327778 MB   -->
0,0325193 MB   -->
0,032095 MB    -->

Last edited by vbe; 04-20-2018 at 10:51 AM..
# 2  
Old 04-20-2018
Welcome aynar,

I have a few to questions pose in response first:-
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.
# 3  
Old 04-20-2018
until now i've changed the output to that


but i have no idea how to do the rest
i have the idea but i don't know how to apply it
i dont even know if it's possible to do a loop that verify in the second column and and show me for each ip the total of the corresponding number

Last edited by vgersh99; 04-20-2018 at 11:56 AM.. Reason: code tags, please!
# 4  
Old 04-20-2018
If you just want them listed together, the sort command would do that. if you only want "". grep is something to try.

That's where I stop for now. You will learn it and retain it much better if you look up those commands and experiment with how to use them.

P.S. Just saw that you removed a few things from each line. That isn't necessary.

Last edited by wbport; 04-20-2018 at 11:53 AM.. Reason: P.S.
# 5  
Old 04-20-2018
do you want to group or to sum up by ip?
This User Gave Thanks to vgersh99 For This Post:
aynar (04-20-2018)
# 6  
Old 04-20-2018
thanks for your help

it's no about it's just an exemple i want to know for how much bandwidth is consumed by each ip address
do for each ip i want to have the total of numbers

---------- Post updated at 09:58 AM ---------- Previous update was at 09:57 AM ----------

that's it sum up by ip
# 7  
Old 04-20-2018
awk -F'[ :]' '{a[$(NF-1)]+=$1} END{for(i in a) printf("%s -> %.7f\n", i, a[i])}' myFile

This User Gave Thanks to vgersh99 For This Post:
aynar (04-20-2018)

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Reading multiple lines with condition dc@bos Shell Programming and Scripting 4 09-26-2014 03:41 AM
Remove duplicate values with condition jiam912 Shell Programming and Scripting 2 06-23-2014 07:22 PM
Print certain lines based on condition ckwan Shell Programming and Scripting 11 08-16-2013 09:43 AM
Grep certain lines with condition radius UNIX for Dummies Questions & Answers 4 05-07-2013 05:04 PM
Print every 5 lines with special condition jacobs.smith Shell Programming and Scripting 13 03-06-2013 05:06 AM
Need to delete all lines where any line meets a condition dbiggied Shell Programming and Scripting 7 10-24-2012 01:59 PM
remove duplicate lines with condition vlm Shell Programming and Scripting 2 05-03-2012 01:48 PM
selecting and deleting specific lines with condition vjramana Shell Programming and Scripting 9 09-13-2011 08:45 AM
Perl XML, find matching condition and grep lines and put the lines somewhere else tententen Shell Programming and Scripting 4 11-03-2010 09:55 PM
Remove lines from XML based on condition giles.cardew Shell Programming and Scripting 3 08-24-2010 04:05 PM
To read the values and to use in the where condition venkatesht Shell Programming and Scripting 10 08-12-2010 05:01 AM
Removing lines with condition jaysean Shell Programming and Scripting 4 07-01-2010 12:03 AM
Count the number of lines in a file with one condition jimmy_y Shell Programming and Scripting 1 02-10-2010 12:23 AM
numbering lines according to a condition elionba82 Shell Programming and Scripting 3 01-26-2009 10:03 AM
Help!! Need script to read files and add values by lines... dhuertas Shell Programming and Scripting 3 09-16-2007 12:14 AM