Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Want the UNIX code - I want to sum of the 1st column wherever the first 2nd and 3rd columns r equal Post 302930044 by ongoto on Monday 29th of December 2014 08:43:42 PM
Old 12-29-2014
Another bash attempt...
Code:
#!/bin/bash

hist=./hist
data=./abc.data
sort -k 2 -u $data -o $hist

while read a b
do
    a=0
    while read aa bb
    do
        if [[ "$bb" == $b ]]; then
            a=$(( $a + $aa ))
        fi
    done < $data
    printf "%s %s\n" $a "$b"
done < $hist
rm $hist

# output
# --------------------
# 17690 0 subscriberCreate
# 32 0 subscriberPaymentMethodChange
# 3220 0 subscriberProfileUpdate
# 15546 0 subscriberStatusChange
# 25 4020100 subscriberProfileUpdate
# 2 4020129 subscriberStatusChange
# 2 4020307 subscriberCreate


Last edited by ongoto; 12-29-2014 at 10:00 PM..
This User Gave Thanks to ongoto For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help sum columns by break in first column with awk or sed or something.

I have some data that is something like this? item: onhand counted location ITEM0001 1 0 a1 ITEM0001 0 1 a2 ITEM0002 5 0 b5 ITEM0002 0 6 c1 I want to sum up... (6 Replies)
Discussion started by: syadnom
6 Replies

2. Shell Programming and Scripting

sum multiple columns based on column value

i have a file - it will be in sorted order on column 1 abc 0 1 abc 2 3 abc 3 5 def 1 7 def 0 1 -------- i'd like (awk maybe?) to get the results (any ideas)??? abc 5 9 def 1 8 (2 Replies)
Discussion started by: jjoe
2 Replies

3. Shell Programming and Scripting

grep data on 2nd line and 3rd column

How do I grep/check the on-hand value on the second line of show_prod script below? In this case it's a "3". So if it's > 0, then run_this, otherwise, quit. > ./show_prod Product Status Onhand Price shoe OK 3 1.1 (6 Replies)
Discussion started by: joker_789us
6 Replies

4. Shell Programming and Scripting

split on the basis of 2nd and 3rd column

file A aa 22 48 ab 22 48 tcf 50 76 gf 50 76 h 89 100 yh 89 100 how can we split the file on the basis of common 2 and third column output like file A-1 aa 22 48 ab 22 48 file A-2 cf 50 76 gf 50 76 (3 Replies)
Discussion started by: cdfd123
3 Replies

5. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

6. 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

7. Linux

Print the 1st column and the value in 2nd or 3rd column if that is different from the values in 1st

I have file that looks like this, DIP-17571N|refseq:NP_651151 DIP-17460N|refseq:NP_511165|uniprotkb:P45890 DIP-17571N|refseq:NP_651151 DIP-19241N|refseq:NP_524261 DIP-19241N|refseq:NP_524261 DIP-17151N|refseq:NP_524316|uniprotkb:O16797 DIP-19588N|refseq:NP_731165 ... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

8. Shell Programming and Scripting

Sum of Columns Base on First Column

Input :- Hd1;Hd2:hd3;Hd4;Hd5 X;1;2;3;4 Y;2;3;5;6 Z;3;5;6;7 X;10;11;24;16 Y;11;23;21;1 Z;10;13;14;15 X;0;1;2;0 K;0;0;0;0 K;0;0;0;0 I want Sum Data base on first column; Hd1;Hd2:hd3;Hd4;Hd5 X;11;14;29;20 Y;12;26;26;7 Z;13;18;20;22 K;0;0;0;0 (4 Replies)
Discussion started by: pareshkp
4 Replies

9. Shell Programming and Scripting

awk to Sum columns when other column has duplicates and append one column value to another with Care

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (1 Reply)
Discussion started by: as7951
1 Replies

10. UNIX for Beginners Questions & Answers

Copy columns from one file into another and get sum of column values and row count

I have a file abc.csv, from which I need column 24(PurchaseOrder_TotalCost) to get the sum_of_amounts with date and row count into another file say output.csv abc.csv- UTF-8,,,,,,,,,,,,,,,,,,,,,,,,, ... (6 Replies)
Discussion started by: Tahir_M
6 Replies
Distr(3pm)						User Contributed Perl Documentation						Distr(3pm)

NAME
PDL::Stats::Distr -- parameter estimations and probability density functions for distributions. DESCRIPTION
Parameter estimate is maximum likelihood estimate when there is closed form estimate, otherwise it is method of moments estimate. SYNOPSIS
use PDL::LiteF; use PDL::Stats::Distr; # do a frequency (probability) plot with fitted normal curve my ($xvals, $hist) = $data->hist; # turn frequency into probability $hist /= $data->nelem; # get maximum likelihood estimates of normal curve parameters my ($m, $v) = $data->mle_gaussian(); # fitted normal curve probabilities my $p = $xvals->pdf_gaussian($m, $v); use PDL::Graphics::PGPLOT::Window; my $win = pgwin( Dev=>"/xs" ); $win->bin( $hist ); $win->hold; $win->line( $p, {COLOR=>2} ); $win->close; Or, play with different distributions with plot_distr :) $data->plot_distr( 'gaussian', 'lognormal' ); FUNCTIONS
mme_beta Signature: (a(n); float+ [o]alpha(); float+ [o]beta()) my ($a, $b) = $data->mme_beta(); beta distribution. pdf: f(x; a,b) = 1/B(a,b) x^(a-1) (1-x)^(b-1) mme_beta does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pdf_beta Signature: (x(); a(); b(); float+ [o]p()) probability density function for beta distribution. x defined on [0,1]. pdf_beta does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mme_binomial Signature: (a(n); int [o]n_(); float+ [o]p()) my ($n, $p) = $data->mme_binomial; binomial distribution. pmf: f(k; n,p) = (n k) p^k (1-p)^(n-k) for k = 0,1,2..n mme_binomial does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pmf_binomial Signature: (ushort x(); ushort n(); p(); float+ [o]out()) probability mass function for binomial distribution. pmf_binomial does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mle_exp Signature: (a(n); float+ [o]l()) my $lamda = $data->mle_exp; exponential distribution. mle same as method of moments estimate. mle_exp does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pdf_exp Signature: (x(); l(); float+ [o]p()) probability density function for exponential distribution. pdf_exp does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mme_gamma Signature: (a(n); float+ [o]shape(); float+ [o]scale()) my ($shape, $scale) = $data->mme_gamma(); two-parameter gamma distribution mme_gamma does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pdf_gamma Signature: (x(); a(); t(); float+ [o]p()) probability density function for two-parameter gamma distribution. pdf_gamma does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mle_gaussian Signature: (a(n); float+ [o]m(); float+ [o]v()) my ($m, $v) = $data->mle_gaussian(); gaussian aka normal distribution. same results as $data->average and $data->var. mle same as method of moments estimate. mle_gaussian does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pdf_gaussian Signature: (x(); m(); v(); float+ [o]p()) probability density function for gaussian distribution. pdf_gaussian does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mle_geo Signature: (a(n); float+ [o]p()) geometric distribution. mle same as method of moments estimate. mle_geo does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pmf_geo Signature: (ushort x(); p(); float+ [o]out()) probability mass function for geometric distribution. x >= 0. pmf_geo does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mle_geosh Signature: (a(n); float+ [o]p()) shifted geometric distribution. mle same as method of moments estimate. mle_geosh does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pmf_geosh Signature: (ushort x(); p(); float+ [o]out()) probability mass function for shifted geometric distribution. x >= 1. pmf_geosh does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mle_lognormal Signature: (a(n); float+ [o]m(); float+ [o]v()) my ($m, $v) = $data->mle_lognormal(); lognormal distribution. maximum likelihood estimation. mle_lognormal does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mme_lognormal Signature: (a(n); float+ [o]m(); float+ [o]v()) my ($m, $v) = $data->mme_lognormal(); lognormal distribution. method of moments estimation. mme_lognormal does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pdf_lognormal Signature: (x(); m(); v(); float+ [o]p()) probability density function for lognormal distribution. x > 0. v > 0. pdf_lognormal does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mme_nbd Signature: (a(n); float+ [o]r(); float+ [o]p()) my ($r, $p) = $data->mme_nbd(); negative binomial distribution. pmf: f(x; r,p) = (x+r-1 r-1) p^r (1-p)^x for x=0,1,2... mme_nbd does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pmf_nbd Signature: (ushort x(); r(); p(); float+ [o]out()) probability mass function for negative binomial distribution. pmf_nbd does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mme_pareto Signature: (a(n); float+ [o]k(); float+ [o]xm()) my ($k, $xm) = $data->mme_pareto(); pareto distribution. pdf: f(x; k,xm) = k xm^k / x^(k+1) for x >= xm > 0. mme_pareto does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pdf_pareto Signature: (x(); k(); xm(); float+ [o]p()) probability density function for pareto distribution. x >= xm > 0. pdf_pareto does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. mle_poisson Signature: (a(n); float+ [o]l()) my $lamda = $data->mle_poisson(); poisson distribution. pmf: f(x;l) = e^(-l) * l^x / x! mle_poisson does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. pmf_poisson Signature: (ushort x(); l(); float+ [o]p()) probability mass function for poisson distribution. pmf_poisson does handle bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. plot_distr Plots data distribution. When given specific distribution(s) to fit, returns % ref to sum log likelihood and parameter values under fitted distribution(s). See FUNCTIONS above for available distributions. Default options (case insensitive): MAXBN => 20, # see PDL::Graphics::PGPLOT::Window for next options WIN => undef, # pgwin object. not closed here if passed # allows comparing multiple distr in same plot # set env before passing WIN DEV => '/xs' , # open and close dev for plotting if no WIN # defaults to '/png' in Windows COLOR => 1, # color for data distr Usage: # yes it threads :) my $data = grandom( 500, 3 )->abs; # ll on plot is sum across 3 data curves my ($ll, $pars) = $data->plot_distr( 'gaussian', 'lognormal', {DEV=>'/png'} ); # pars are from normalized data (ie data / bin_size) print "$_ @{$pars->{$_}} " for (sort keys %$pars); print "$_ $ll->{$_} " for (sort keys %$ll); DEPENDENCIES
GSL - GNU Scientific Library SEE ALSO
PDL::Graphics::PGPLOT PDL::GSL::CDF AUTHOR
Copyright (C) 2009 Maggie J. Xiong <maggiexyz users.sourceforge.net> All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation as described in the file COPYING in the PDL distribution. perl v5.14.2 2012-06-04 Distr(3pm)
All times are GMT -4. The time now is 07:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy