Sponsored Content
Top Forums Shell Programming and Scripting Get the SUM of TWO columns SEPARATELY by doing GROUP BY on other columns Post 302881201 by machomaddy on Friday 27th of December 2013 05:46:20 AM
Old 12-27-2013
Get the SUM of TWO columns SEPARATELY by doing GROUP BY on other columns

My File looks like:

"|" -> Field separator
Code:
A|B|C|100|1000
D|E|F|1|2
G|H|I|0|7
D|E|F|1|2
A|B|C|10|10000
G|H|I|0|7
A|B|C|1|100
D|E|F|1|2

I need to do a SUM on Col. 5 and Col.6 by grouping on Col 1,2 & 3

My expected output is:

Code:
A|B|C|111|11100
D|E|F|3|6
G|H|I|1|16

Can this be done using awk? I have done this kind of SUM for a single column but I'm stuck up when I'm doing SUM for two columns
Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sum columns

can anyone help me how do i add the colums using awk seperated by character @. for eg i have 3@4 2@9 5@1 the result should be 10 14 i tried using { sum+= $1 } END { print sum } but it just gives the result 10. can anyone help me with this one thank you and best regards (7 Replies)
Discussion started by: phone_book
7 Replies

2. Shell Programming and Scripting

sum of three columns

Hi All, I have like this M17XX-050-01 0100000000 QQSSS 0.0000e+00 1.712E+06 1.255E+07 0.0000e+00 0.0000e+00 1.722E+06 1.263E+07 0.0000e+00 ... 0.0000e+00 1.204E+06 8.829E+06 0.0000e+00 M17XX-050-01 0100000000 WWSSS 0.0000e+00 7.564E+03 1.165E+01 0.0000e+00... (6 Replies)
Discussion started by: f_o_555
6 Replies

3. Shell Programming and Scripting

Sum of three columns - in 4N columns file

Hi All, happy new year. I have a file with 4xN columns like 0.0000e+00 0.0000e+00 7.199E+07 7.123E+07 6.976E+07 6.482E+07 5.256E+07 2.523E+07 0.0000e+00 0.0000e+00 8.641E+07 8.550E+07 8.373E+07 7.780E+07 6.309E+07 3.028E+07... (8 Replies)
Discussion started by: f_o_555
8 Replies

4. Shell Programming and Scripting

how can i group by same columns by another columns in Bash

how can i group by same columns by another columns in Bash Eq. this is a csv file Co1 Co2 Co3 Co4 A A 1,000 1,000 A B 2,000 1,250 A A 2,000 3,002 A C 2,000 3,005 how can i get the result of like this Co1 Co2 Co3 Co4 A A 3,000 ... (5 Replies)
Discussion started by: qjlongs
5 Replies

5. Shell Programming and Scripting

Sum columns

Hi All, I'm new to this forum. So please be patience with me! :) I have a file that looks like this (all rows have the same number of columns): 19 20 30 15 17 38 51 60 74 85 96 07 .... 10 20 44 59 39 88 13 77 30 10 11 12 .... . . . I want to sum the value of first field to all the... (2 Replies)
Discussion started by: Aderson Nascime
2 Replies

6. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

7. Shell Programming and Scripting

Sum of all columns

Hi Friends, I have a file with fields separated with comma. How to print sum of each field of the file? Eg: input file 1,3,6,7 2,1,2,1 0,1,1,0 I want to sum each field separately. Output file 3,5,9,8 Thanks, Suresh (2 Replies)
Discussion started by: suresh3566
2 Replies

8. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns satisfy the condition

HI All, I'm embedding SQL query in Script which gives following output: Assignee Group Total ABC Group1 17 PQR Group2 5 PQR Group3 6 XYZ Group1 10 XYZ Group3 5 I have saved the above output in a file. How do i sum up the contents of this output so as to get following output: ... (4 Replies)
Discussion started by: Khushbu
4 Replies

9. Shell Programming and Scripting

Sum of Columns

HI Guys, I gave Input file F.Txt ID H1 H2 H3 H4 H5 A 5 6 7 8 9 B 4 65 4 4 7 C 4 4 4 4 4 D 4 4 4 4 4 Output :- ID H1 H2 H3 H4 H5 Total 17 79 19 20 24 Sum of Each Columns (8 Replies)
Discussion started by: pareshkp
8 Replies

10. UNIX for Beginners Questions & Answers

Group by columns and add sum in new columns

Dear Experts, I have input file which is comma separated, has 4 columns like below, BRAND,COUNTRY,MODEL,COUNT NIKE,USA,DUMMY,5 NIKE,USA,ORIGINAL,10 PUMA,FRANCE,DUMMY,20 PUMA,FRANCE,ORIGINAL,15 ADIDAS,ITALY,DUMMY,50 ADIDAS,ITALY,ORIGINAL,50 SPIKE,CHINA,DUMMY,1O And expected output add... (2 Replies)
Discussion started by: ricky1991
2 Replies
wxListCtrl(3erl)					     Erlang Module Definition						  wxListCtrl(3erl)

NAME
wxListCtrl - See external documentation: wxListCtrl. DESCRIPTION
See external documentation: wxListCtrl . This class is derived (and can use functions) from: wxControl wxWindow wxEvtHandler DATA TYPES
wxListCtrl() : An object reference, The representation is internal and can be changed without notice. It can't be used for comparsion stored on disc or distributed for use on other nodes. EXPORTS
new() -> wxListCtrl() See external documentation . new(Parent::wxWindow() (see module wxWindow)) -> wxListCtrl() Equivalent to new(Parent, []) . new(Parent::wxWindow() (see module wxWindow), Options::[Option]) -> wxListCtrl() Types Option = {winid, integer()} | {pos, {X::integer(), Y::integer()}} | {size, {W::integer(), H::integer()}} | {style, integer()} | {validator, wx() (see module wx)} See external documentation . arrange(This::wxListCtrl()) -> bool() Equivalent to arrange(This, []) . arrange(This::wxListCtrl(), Options::[Option]) -> bool() Types Option = {flag, integer()} See external documentation . assignImageList(This::wxListCtrl(), ImageList::wxImageList() (see module wxImageList), Which::integer()) -> ok See external documentation . clearAll(This::wxListCtrl()) -> ok See external documentation . create(This::wxListCtrl(), Parent::wxWindow() (see module wxWindow)) -> bool() Equivalent to create(This, Parent, []) . create(This::wxListCtrl(), Parent::wxWindow() (see module wxWindow), Options::[Option]) -> bool() Types Option = {winid, integer()} | {pos, {X::integer(), Y::integer()}} | {size, {W::integer(), H::integer()}} | {style, integer()} | {validator, wx() (see module wx)} See external documentation . deleteAllItems(This::wxListCtrl()) -> bool() See external documentation . deleteColumn(This::wxListCtrl(), Col::integer()) -> bool() See external documentation . deleteItem(This::wxListCtrl(), Item::integer()) -> bool() See external documentation . editLabel(This::wxListCtrl(), Item::integer()) -> wxTextCtrl() (see module wxTextCtrl) See external documentation . ensureVisible(This::wxListCtrl(), Item::integer()) -> bool() See external documentation . findItem(This::wxListCtrl(), Start::integer(), Str::string()) -> integer() Equivalent to findItem(This, Start, Str, []) . findItem(This::wxListCtrl(), Start::integer(), X::string() | term(), X::term() | integer()) -> integer() See external documentation . Alternatives: findItem(This::wxListCtrl(), Start::integer(), Str::string(), [Option]) -> integer() Option = {partial, bool()} findItem(This::wxListCtrl(), Start::integer(), Pt::{X::integer(),Y::integer()}, Direction::integer()) -> integer() getColumn(This::wxListCtrl(), Col::integer(), Item::wxListItem() (see module wxListItem)) -> bool() See external documentation . getColumnCount(This::wxListCtrl()) -> integer() See external documentation . getColumnWidth(This::wxListCtrl(), Col::integer()) -> integer() See external documentation . getCountPerPage(This::wxListCtrl()) -> integer() See external documentation . getEditControl(This::wxListCtrl()) -> wxTextCtrl() (see module wxTextCtrl) See external documentation . getImageList(This::wxListCtrl(), Which::integer()) -> wxImageList() (see module wxImageList) See external documentation . getItem(This::wxListCtrl(), Info::wxListItem() (see module wxListItem)) -> bool() See external documentation . getItemBackgroundColour(This::wxListCtrl(), Item::integer()) -> colour() (see module wx) See external documentation . getItemCount(This::wxListCtrl()) -> integer() See external documentation . getItemData(This::wxListCtrl(), Item::integer()) -> integer() See external documentation . getItemFont(This::wxListCtrl(), Item::integer()) -> wxFont() (see module wxFont) See external documentation . getItemPosition(This::wxListCtrl(), Item::integer(), Pos::{X::integer(), Y::integer()}) -> bool() See external documentation . getItemRect(This::wxListCtrl(), Item::integer(), Rect::{X::integer(), Y::integer(), W::integer(), H::integer()}) -> bool() Equivalent to getItemRect(This, Item, Rect, []) . getItemRect(This::wxListCtrl(), Item::integer(), Rect::{X::integer(), Y::integer(), W::integer(), H::integer()}, Options::[Option]) -> bool() Types Option = {code, integer()} See external documentation . getItemSpacing(This::wxListCtrl()) -> {W::integer(), H::integer()} See external documentation . getItemState(This::wxListCtrl(), Item::integer(), StateMask::integer()) -> integer() See external documentation . getItemText(This::wxListCtrl(), Item::integer()) -> string() See external documentation . getItemTextColour(This::wxListCtrl(), Item::integer()) -> colour() (see module wx) See external documentation . getNextItem(This::wxListCtrl(), Item::integer()) -> integer() Equivalent to getNextItem(This, Item, []) . getNextItem(This::wxListCtrl(), Item::integer(), Options::[Option]) -> integer() Types Option = {geometry, integer()} | {state, integer()} See external documentation . getSelectedItemCount(This::wxListCtrl()) -> integer() See external documentation . getTextColour(This::wxListCtrl()) -> colour() (see module wx) See external documentation . getTopItem(This::wxListCtrl()) -> integer() See external documentation . getViewRect(This::wxListCtrl()) -> {X::integer(), Y::integer(), W::integer(), H::integer()} See external documentation . hitTest(This::wxListCtrl(), Point::{X::integer(), Y::integer()}) -> {integer(), Flags::integer()} See external documentation . insertColumn(This::wxListCtrl(), Col::integer(), X::string() | term()) -> integer() See external documentation . Alternatives: insertColumn(This::wxListCtrl(), Col::integer(), Heading::string()) -> insertColumn(This,Col,Heading, []) insertColumn(This::wxListCtrl(), Col::integer(), Info::wxListItem:wxListItem()) -> integer() insertColumn(This::wxListCtrl(), Col::integer(), Heading::string(), Options::[Option]) -> integer() Types Option = {format, integer()} | {width, integer()} See external documentation . insertItem(This::wxListCtrl(), Info::wxListItem() (see module wxListItem)) -> integer() See external documentation . insertItem(This::wxListCtrl(), Index::integer(), X::integer() | string()) -> integer() See external documentation . Alternatives: insertItem(This::wxListCtrl(), Index::integer(), ImageIndex::integer()) -> integer() insertItem(This::wxListCtrl(), Index::integer(), Label::string()) -> integer() insertItem(This::wxListCtrl(), Index::integer(), Label::string(), ImageIndex::integer()) -> integer() See external documentation . refreshItem(This::wxListCtrl(), Item::integer()) -> ok See external documentation . refreshItems(This::wxListCtrl(), ItemFrom::integer(), ItemTo::integer()) -> ok See external documentation . scrollList(This::wxListCtrl(), Dx::integer(), Dy::integer()) -> bool() See external documentation . setBackgroundColour(This::wxListCtrl(), Colour::colour() (see module wx)) -> bool() See external documentation . setColumn(This::wxListCtrl(), Col::integer(), Item::wxListItem() (see module wxListItem)) -> bool() See external documentation . setColumnWidth(This::wxListCtrl(), Col::integer(), Width::integer()) -> bool() See external documentation . setImageList(This::wxListCtrl(), ImageList::wxImageList() (see module wxImageList), Which::integer()) -> ok See external documentation . setItem(This::wxListCtrl(), Info::wxListItem() (see module wxListItem)) -> bool() See external documentation . setItem(This::wxListCtrl(), Index::integer(), Col::integer(), Label::string()) -> integer() Equivalent to setItem(This, Index, Col, Label, []) . setItem(This::wxListCtrl(), Index::integer(), Col::integer(), Label::string(), Options::[Option]) -> integer() Types Option = {imageId, integer()} See external documentation . setItemBackgroundColour(This::wxListCtrl(), Item::integer(), Col::colour() (see module wx)) -> ok See external documentation . setItemCount(This::wxListCtrl(), Count::integer()) -> ok See external documentation . setItemData(This::wxListCtrl(), Item::integer(), Data::integer()) -> bool() See external documentation . setItemFont(This::wxListCtrl(), Item::integer(), F::wxFont() (see module wxFont)) -> ok See external documentation . setItemImage(This::wxListCtrl(), Item::integer(), Image::integer()) -> bool() Equivalent to setItemImage(This, Item, Image, []) . setItemImage(This::wxListCtrl(), Item::integer(), Image::integer(), Options::[Option]) -> bool() Types Option = {selImage, integer()} See external documentation . setItemColumnImage(This::wxListCtrl(), Item::integer(), Column::integer(), Image::integer()) -> bool() See external documentation . setItemPosition(This::wxListCtrl(), Item::integer(), Pos::{X::integer(), Y::integer()}) -> bool() See external documentation . setItemState(This::wxListCtrl(), Item::integer(), State::integer(), StateMask::integer()) -> bool() See external documentation . setItemText(This::wxListCtrl(), Item::integer(), Str::string()) -> ok See external documentation . setItemTextColour(This::wxListCtrl(), Item::integer(), Col::colour() (see module wx)) -> ok See external documentation . setSingleStyle(This::wxListCtrl(), Style::integer()) -> ok Equivalent to setSingleStyle(This, Style, []) . setSingleStyle(This::wxListCtrl(), Style::integer(), Options::[Option]) -> ok Types Option = {add, bool()} See external documentation . setTextColour(This::wxListCtrl(), Col::colour() (see module wx)) -> ok See external documentation . setWindowStyleFlag(This::wxListCtrl(), Style::integer()) -> ok See external documentation . sortItems(This::wxListCtrl(), SortCallBack::function()) -> boolean() Sort the items in the list control SortCalBack(Item1,Item2) -> integer() SortCallBack receives the client data associated with two items to compare, and should return 0 if the items are equal, a negative value if the first item is less than the second one and a positive value if the first item is greater than the second one. NOTE: The callback may not call other processes. destroy(This::wxListCtrl()) -> ok Destroys this object, do not use object again AUTHORS
<> wxErlang 0.98.9 wxListCtrl(3erl)
All times are GMT -4. The time now is 08:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy