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
Bio::Tools::EUtilities::HistoryI(3pm)			User Contributed Perl Documentation		     Bio::Tools::EUtilities::HistoryI(3pm)

NAME
Bio::Tools::EUtilities::HistoryI - simple extension of EUtilDataI interface class for classes which hold NCBI server history data SYNOPSIS
#should work for any class which is-a HistoryI if ($obj->has_History) { # do something here } ($webenv, $querykey) = $obj->history; $obj->history($webenv, $querykey); $webenv = $obj->get_webenv; $query_key = $obj->get_query_key; DESCRIPTION
This class extends methods for any EUtilDataI implementation allow instances to dealwith NCBI history data (WebEnv and query_key). These can be used as parameters for further queries against data sets stored on the NCBI server, much like NCBI's Entrez search history. These are important when one wants to run complex queries using esearch, retrieve related data using elink, and retrieve large datasets using epost/efetch. The simplest implementation is Bio::Tools::EUtilities::History, which holds the history data for epost. See also Bio::Tools::EUtilities::Query (esearch) and Bio::Tools::EUtilities::LinkSet (elink), which also implement HistoryI. FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to one of the Bioperl mailing lists. Your participation is much appreciated. bioperl-l@lists.open-bio.org - General discussion http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track the bugs and their resolution. Bug reports can be submitted via the web. https://redmine.open-bio.org/projects/bioperl/ AUTHOR
Email cjfields at bioperl dot org APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ history Title : history Usage : my ($webenv, $qk) = $hist->history Function : Get/Set two-element list of webenv() and query_key() Returns : array Args : two-element list of webenv, querykey get_webenv Title : get_webenv Usage : my $webenv = $hist->get_webenv Function : returns web environment key needed to retrieve results from NCBI server Returns : string (encoded key) Args : none get_query_key Title : get_query_key Usage : my $qk = $hist->get_query_key Function : returns query key (integer) for the history number for this session Returns : integer Args : none perl v5.14.2 2012-03-02 Bio::Tools::EUtilities::HistoryI(3pm)
All times are GMT -4. The time now is 11:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy