Home
Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Add the values of the lines according to a condition

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 8  
Old 04-20-2018
thanks for your response
i dont understand the commande very well
and when i tried it t got that result

-> 9,9555336


seem like it give the total of everything
not per ip
# 9  
Old 04-20-2018
Quote:
Originally Posted by aynar
thanks for your response
i dont understand the commande very well
and when i tried it t got that result

-> 9,9555336


seem like it give the total of everything
not per ip
the code is based on a data sample you provided in post 1.

The output should be similar to: 100.1.1.15 -> 8,0000000
# 10  
Old 04-20-2018
As the sample in post#1 has commas in lieu of decimal dots, you might need to convert those first. Try this small adaption of vgersh99's code:
Code:
awk -F'[ :]' '
        {sub (/,/, ".", $1)
         a[$(NF-1)] += $1
        }
END     {for(i in a) printf("%s -> %.7f\n", i, a[i])
        }
' file
100.1.1.15 -> 9.6030529
100.1.1.64 -> 0.1469163
100.1.1.75 -> 0.0784025

# 11  
Old 04-20-2018
RudiC,
the OP's locale might be different, but good catch.
# 12  
Old 04-20-2018
I was also thinking of DOS line terminators (<CR>, <carriage return, ^M, \r, or 0x0D), which would explain the strange output s/he posted, but there were none in the sample data.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk to capture lines that meet either condition cmccabe Shell Programming and Scripting 2 08-03-2017 08:48 AM
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
Comparing all lines in a column with another is condition is met amits22 Shell Programming and Scripting 4 06-25-2013 05:08 AM
Grep certain lines with condition radius UNIX for Dummies Questions & Answers 4 05-07-2013 05:04 PM
remove duplicate lines with condition vlm Shell Programming and Scripting 2 05-03-2012 01:48 PM
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
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
numbering lines according to a condition elionba82 Shell Programming and Scripting 3 01-26-2009 10:03 AM


All times are GMT -4. The time now is 09:23 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password