Sponsored Content
Full Discussion: sum values based on ID
Top Forums UNIX for Dummies Questions & Answers sum values based on ID Post 302721811 by agama on Thursday 25th of October 2012 08:36:29 PM
Old 10-25-2012
Have a go with this:

Code:
awk '
    {
        split( $1, a, ":" );
        sum[a[1]] += $NF;
    }
    END {
        for( s in sum )
            print s, sum[s];
    }
'   input-file

Sums values in the last column, using the first column's name after truncating characters to the right of the colon.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to sum column 1 values

I have a file file like this. I want to sum all column 1 values. input A 2 A 3 A 4 B 4 B 2 Out put A 9 B 6 (3 Replies)
Discussion started by: suresh3566
3 Replies

2. Shell Programming and Scripting

how to sum values from 2 different files?

Hi I am trying to add count values from two different files into one file. Could any body please suggest me best command to do this? My problem was as follows: a.txt b.txt c.txt 10 20 30(needed) i tried cat a.txt b.txt > c.txt (its not adding the values) Thanks in advance.. Praveen (8 Replies)
Discussion started by: npk2210
8 Replies

3. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

4. Shell Programming and Scripting

How to sum values from top

Hi. Im looking for way to sum numbers from top. For example i have such command top -b -n | grep Cpu | cut -c 35 - 39 which give me output 97.0 . Ho can i do with that value any arithmetic actions (for example 97.0 +1)? Using c = $((top -b -n | grep Cpu | cut -c 35 - 39)) gives me... (8 Replies)
Discussion started by: qdf
8 Replies

5. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

6. Shell Programming and Scripting

How to sum up two decimal values?

I am running the following script : cat ind_sls_extr_UX.out_sorted | while read each_rec do count=`echo "${each_rec}" | cut -c1-2` if then final_amount=0 amount=`echo "${each_rec}" | cut -c280-287` echo "${amount}" final_amount=`expr ${amount} + ${amount}` ... (7 Replies)
Discussion started by: mady135
7 Replies

7. Shell Programming and Scripting

Getting a sum of column values

I have a file in the following layout: 201008005946873001846130058030701006131840000000000000000000 201008006784994001154259058033001009527844000000000000000000 201008007323067002418095058034801002418095000000000000000000 201008007697126001722141058029101002214158000000000000000000... (2 Replies)
Discussion started by: jclanc8
2 Replies

8. UNIX for Dummies Questions & Answers

Sum up values followed by pattern

I have a file with data merged from multiple files. File contains header, data and trailer of multiple files. The trailer starts with 99 and delimiter is ~. Trailer 99~120 99~30 As it is a merged file we i have multiple lines followed by 99~. Need help to find sum of values which are there... (4 Replies)
Discussion started by: santoshdrkr
4 Replies

9. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

10. Shell Programming and Scripting

How to sum the value with negative values?

Hi Gurus, I have requirement need to sum the value, the logic is if the value is negative then time -1, I tried below two ways. one is failed, another one doesn't work. awk -F"," '{if($8< 0 $8*-1 else $8) sum+=$8}{print sum, $8} END{printf("%.2f\n",sum)}' awk -F","... (4 Replies)
Discussion started by: ken6503
4 Replies
DBIx::Class::ResultSetColumn(3) 			User Contributed Perl Documentation			   DBIx::Class::ResultSetColumn(3)

NAME
DBIx::Class::ResultSetColumn - helpful methods for messing with a single column of the resultset SYNOPSIS
$rs = $schema->resultset('CD')->search({ artist => 'Tool' }); $rs_column = $rs->get_column('year'); $max_year = $rs_column->max; #returns latest year DESCRIPTION
A convenience class used to perform operations on a specific column of a resultset. METHODS
new my $obj = DBIx::Class::ResultSetColumn->new($rs, $column); Creates a new resultset column object from the resultset and column passed as params. Used internally by "get_column" in DBIx::Class::ResultSet. as_query Arguments: none Return Value: [ $sql, @bind_values ] Returns the SQL query and bind vars associated with the invocant. This is generally used as the RHS for a subquery. next Arguments: none Return Value: $value Returns the next value of the column in the resultset (or "undef" if there is none). Much like "next" in DBIx::Class::ResultSet but just returning the one value. all Arguments: none Return Value: @values Returns all values of the column in the resultset (or "undef" if there are none). Much like "all" in DBIx::Class::ResultSet but returns values rather than result objects. reset Arguments: none Return Value: $self Resets the underlying resultset's cursor, so you can iterate through the elements of the column again. Much like "reset" in DBIx::Class::ResultSet. first Arguments: none Return Value: $value Resets the underlying resultset and returns the next value of the column in the resultset (or "undef" if there is none). Much like "first" in DBIx::Class::ResultSet but just returning the one value. single Arguments: none Return Value: $value Much like "single" in DBIx::Class::ResultSet fetches one and only one column value using the cursor directly. If additional rows are present a warning is issued before discarding the cursor. min Arguments: none Return Value: $lowest_value my $first_year = $year_col->min(); Wrapper for ->func. Returns the lowest value of the column in the resultset (or "undef" if there are none). min_rs Arguments: none Return Value: $resultset my $rs = $year_col->min_rs(); Wrapper for ->func_rs for function MIN(). max Arguments: none Return Value: $highest_value my $last_year = $year_col->max(); Wrapper for ->func. Returns the highest value of the column in the resultset (or "undef" if there are none). max_rs Arguments: none Return Value: $resultset my $rs = $year_col->max_rs(); Wrapper for ->func_rs for function MAX(). sum Arguments: none Return Value: $sum_of_values my $total = $prices_col->sum(); Wrapper for ->func. Returns the sum of all the values in the column of the resultset. Use on varchar-like columns at your own risk. sum_rs Arguments: none Return Value: $resultset my $rs = $year_col->sum_rs(); Wrapper for ->func_rs for function SUM(). func Arguments: $function Return Value: $function_return_value $rs = $schema->resultset("CD")->search({}); $length = $rs->get_column('title')->func('LENGTH'); Runs a query using the function on the column and returns the value. Produces the following SQL: SELECT LENGTH( title ) FROM cd me func_rs Arguments: $function Return Value: $resultset Creates the resultset that "func()" uses to run its query. throw_exception See "throw_exception" in DBIx::Class::Schema for details. AUTHOR AND CONTRIBUTORS
See AUTHOR and CONTRIBUTORS in DBIx::Class LICENSE
You may distribute this code under the same terms as Perl itself. perl v5.18.2 2014-01-23 DBIx::Class::ResultSetColumn(3)
All times are GMT -4. The time now is 08:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy